How to get Array Value for This..?

Discussion in 'PHP' started by pogung177, Nov 30, 2007.

  1. #1
     Array
    (
        [out] => Array
            (
                [count] => 10
                [offset] => 0
                [products] => Array
                    (
                        [Product] => Array
                            (
                                [0] => Array
                                    (
                                        [adId] => 1221314
                                        [advertiserId] => 6455
                                        [advertiserName] => Baseball Warehouse
                                        [buyUrl] => http://www.tkqlhce.com/click-xxxxxx?url=http%3A%2F%2Fwww.baseballwarehouse.com%2FItemdesc.asp%3Fic%3DSSCGB%26Tp%3D&cjsku=SSCGB
                                        [catalogId] => cjo:262
                                        [currency] => USD
                                        [description] => The definitive guide to men's collegiate baseball programs in the U.S....Regular Price: $27.95...Baseball Warehouse Price: $24.99
                                        [imageUrl] => http://www.bwimages.net/products/sscgb_s.jpg
                                        [inStock] => 
                                        [isbn] => 
                                        [manufacturerName] => TheSportSource
                                        [manufacturerSku] => 
                                        [name] => COLLEGE GUIDE BASEBALL
                                        [price] => 24.99
                                        [retailPrice] => 0.0
                                        [salePrice] => 0.0
                                        [sku] => SSCGB
                                        [upc] => 
                                    )
    
                                [1] => Array
                                    (
                                        [adId] => 121212
                                        [advertiserId] => 434234
                                        [advertiserName] => Baseball Warehouse
                                        [buyUrl] => http://www.dpbolvw.net/click-xxxxxx?url=http%3A%2F%2Fwww.baseballwarehouse.com%2FItemdesc.asp%3Fic%3DBYBVID%26Tp%3D&cjsku=BYBVID
                                        [catalogId] => cjo:262
                                        [currency] => USD
                                        [description] => This creative video is geared for all parents and kids who love baseball. This video is comprised of over 30 great drills that can be played in one's own backyard. This is a true baseball lovers delight that parents will use continually as a resource.
                                        [imageUrl] => http://www.bwimages.net/products/bybvid_s.jpg
                                        [inStock] => 
                                        [isbn] => 
                                        [manufacturerName] => YouthSportsClub
                                        [manufacturerSku] => 
                                        [name] => BACKYARD BASEBALL VIDEO
                                        [price] => 19.99
                                        [retailPrice] => 0.0
                                        [salePrice] => 0.0
                                        [sku] => BYBVID
                                        [upc] => 
                                    )
                              
                            )
                    )
                [totalResults] => 130069
            )
    
    )
    Code (markup):
    Anybody can help, How I can get the value of this deep array.
    I just want to take the value Name, descriptiom and price.

    I have use this foreach still got zero result
    
      foreach ($result as $key => $v) {
    				if($key=="products")
    						{
    						foreach ( $v[product] as $a => $b )
    						{
    			            $description =$b[description];
    						echo "$description";
    						}
    
    						}
    				}
    
    Code (markup):
     
    pogung177, Nov 30, 2007 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Place some "print_r($v);" or "print_r($b);" in the code to be able to see where your pointer currently is and if you need to go deeper.
     
    hogan_h, Nov 30, 2007 IP
  3. krampus

    krampus Active Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    88
    #3
    now let's see..

    this is your array:

    
    $array = array
    (
    	"out" => array
    	(
    		"count" => "10",
    		"offset" => "0",
    		"products" => array
    		(
    			"Product" => array
    			(
    				"0" => array
    				(
    					"adId" => "1221314",
    					"advertiserId" => "6455",
    					"advertiserName" => "Baseball Warehouse",
    					"buyUrl" => "","http://www.tkqlhce.com/click-xxxxxx?url=http%3A%2F%2Fwww.baseballwarehouse.com%2FItemdesc.asp%3Fic%3DSSCGB%26Tp%3D&cjsku=SSCGB",
    					"catalogId" => "cjo:262",
    					"currency" => "USD",
    					"description" => "The definitive guide to men's collegiate baseball programs in the U.S....Regular Price: $27.95...Baseball Warehouse Price: $24.99",
    					"imageUrl" => "http://www.bwimages.net/products/sscgb_s.jpg",
    					"inStock" => "",
    					"isbn" => "",
    					"manufacturerName" => "TheSportSource",
    					"manufacturerSku" => "",
    					"name" => "COLLEGE GUIDE BASEBALL",
    					"price" => "24.99",
    					"retailPrice" => "0.0",
    					"salePrice" => "0.0",
    					"sku" => "SSCGB",
    					"upc" => "",
    				),
    				"1" => array
    				(
    					"adId" => "1221314",
    					"advertiserId" => "6455",
    					"advertiserName" => "Baseball Warehouse",
    					"buyUrl" => "","http://www.tkqlhce.com/click-xxxxxx?url=http%3A%2F%2Fwww.baseballwarehouse.com%2FItemdesc.asp%3Fic%3DSSCGB%26Tp%3D&cjsku=SSCGB",
    					"catalogId" => "cjo:262",
    					"currency" => "USD",
    					"description" => "The definitive guide to men's collegiate baseball programs in the U.S....Regular Price: $27.95...Baseball Warehouse Price: $24.99",
    					"imageUrl" => "http://www.bwimages.net/products/sscgb_s.jpg",
    					"inStock" => "",
    					"isbn" => "",
    					"manufacturerName" => "TheSportSource",
    					"manufacturerSku" => "",
    					"name" => "COLLEGE GUIDE BASEBALL",
    					"price" => "24.99",
    					"retailPrice" => "0.0",
    					"salePrice" => "0.0",
    					"sku" => "SSCGB",
    					"upc" => "",
    				),
    				
    				
    			),
    		),
    	),
    );
    
    Code (markup):
    I used two same product values for this example.

    So.. for this array you can use this code to print your values

    
    // number of products
    $num_Products = count($array["out"]["products"]["Product"]);
    
    for($x = 0; $x < $num_Products; $x++)
    {
    	echo $array["out"]["products"]["Product"][$x]["description"]."<br>";
    	echo $array["out"]["products"]["Product"][$x]["name"]."<br>";
    	echo $array["out"]["products"]["Product"][$x]["price"]."<br>";
    	echo "<hr>";
    }
    
    Code (markup):
    and you will get something like this


    The definitive guide to men's collegiate baseball programs in the U.S....Regular Price: $27.95...Baseball Warehouse Price: $24.99
    COLLEGE GUIDE BASEBALL
    24.99
    _________________________________________________
    The definitive guide to men's collegiate baseball programs in the U.S....Regular Price: $27.95...Baseball Warehouse Price: $24.99
    COLLEGE GUIDE BASEBALL
    24.99
    _________________________________________________


    is it that what you want?
     
    krampus, Nov 30, 2007 IP
    pogung177 likes this.
  4. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #4
    foreach ($results['out']['products']['Product'] as $_product_number){
    	echo "$_product_number[name]<br />";
    	echo "$_product_number[description]<br />";
    	echo "$_product_number[price]<br />";
    	echo '<hr />';
    }
    
    PHP:
     
    selling vcc, Nov 30, 2007 IP
    pogung177 likes this.
  5. krampus

    krampus Active Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    88
    #5
    yes.. that is better.. shorter :)
     
    krampus, Nov 30, 2007 IP
  6. pogung177

    pogung177 Well-Known Member

    Messages:
    415
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    110
    #6
    Thanks Selling_VCC and Kramus. I have give you reputation for your help.
     
    pogung177, Dec 1, 2007 IP
    selling vcc likes this.