playaz Posted March 3, 2006 Share Posted March 3, 2006 Hi guys,Only a few hours til the end of the day and my mind has gone blank and im struggling with some arrays.I have a multi-dimensional array, shown below:[code]Array ( [0] => Array ( [category_id] => 101 [parent_id] => 75 [category] => Microsoft ) [1] => Array ( [category_id] => 100 [parent_id] => 75 [category] => Sun ) [2] => Array ( [category_id] => 102 [parent_id] => 75 [category] => Oracle ) )[/code]I want to grab the 'category_id' for each single element in the array and place this into a variable with a comma seperator.So basically my array above should place the values of 'category_id' into a variable called $in. This variable should be as follows:print $in // outputs '101, 100, 102'Can someone show me how to do this please my brain just seems to have died on me today :) Quote Link to comment Share on other sites More sharing options...
obsidian Posted March 3, 2006 Share Posted March 3, 2006 try something like this:[code]$data = array ( [0] => array ( ['category_id'] => 101, ['parent_id'] => 75, ['category'] => Microsoft ), [1] => array ( ['category_id'] => 100, ['parent_id'] => 75, ['category'] => Sun ), [2] => array ( ['category_id'] => 102, ['parent_id'] => 75, ['category'] => Oracle ) );$cats = array();foreach ($data as $x) { $cats[] = $x['category_id'];}$in = implode(', ', $cats);[/code]hope this helps Quote Link to comment Share on other sites More sharing options...
playaz Posted March 6, 2006 Author Share Posted March 6, 2006 [!--quoteo(post=351385:date=Mar 3 2006, 06:16 PM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Mar 3 2006, 06:16 PM) [snapback]351385[/snapback][/div][div class=\'quotemain\'][!--quotec--]hope this helps[/quote]Cheers mate its much appreciated keep up the good work :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.