Bifter Posted May 23, 2009 Share Posted May 23, 2009 I cannot figure out why this wont work - am I missing something? <?php $products = array(); foreach ($L['products'] as $array) { $products[$array['product-id']['value']] = $array['product-name']['value'] = $array['technology-type']['value']; } foreach ($products as $id => $name => $ttype) { echo '<input type="radio" name="product" value="' . $id . '" /><span>' . $name . '</span> <span>' . $ttype . '</span><br />'; } ?> Thanks for your time. Quote Link to comment https://forums.phpfreaks.com/topic/159381-solved-foreach-array/ Share on other sites More sharing options...
Daniel0 Posted May 23, 2009 Share Posted May 23, 2009 Where is $L['products'] defined? Also, how "doesn't it work"? Quote Link to comment https://forums.phpfreaks.com/topic/159381-solved-foreach-array/#findComment-840680 Share on other sites More sharing options...
Bifter Posted May 23, 2009 Author Share Posted May 23, 2009 $L stores the array: [products] => Array ( [0] => Array ( [product-id] => Array ( [format] => counting [value] => 1235 ) [product-name] => Array ( [format] => text [value] => Home 512k Classic ) [technology-type] => Array ( [format] => text [value] => adsl ) [capped] => Array ( [format] => yesno [value] => Y ) [service-speed] => Array ( [format] => counting [value] => 524288 ) [contention] => Array ( [format] => counting [value] => 50 ) [care-availability] => Array ( [format] => yesno [value] => Y ) [care-level] => Array ( [format] => text [value] => standard ) [realms] => Array ( [0] => Array ( [realm] => Array ( [format] => text [value] => - ) ) ) ) Parse error: syntax error, unexpected T_DOUBLE_ARROW, expecting ')' in /home/ipendpoi/public_html/connect/xml.php on line 106 Quote Link to comment https://forums.phpfreaks.com/topic/159381-solved-foreach-array/#findComment-840683 Share on other sites More sharing options...
thebadbad Posted May 23, 2009 Share Posted May 23, 2009 You should probably leave a link to your last topic, so people can get an idea of what you're trying to do. You've misunderstood how to use the foreach construct. $id and $name are just holders for the key and value of each element in the array $products. To access the technology-type value from your original array, you'll have to add it to $products in the first foreach construct. Here's a way to do it: <?php $products = array(); foreach ($L['products'] as $array) { //add needed info to our new array $products[] = array( 'id' => $array['product-id']['value'], 'name' => $array['product-name']['value'], 'ttype' => $array['technology-type']['value'] ); } //output info stored in arrays in $products foreach ($products as $array) { echo '<input type="radio" name="product" value="' . $array['id'] . '" /><span>' . $array['name'] . ' ' . $array['ttype'] . '</span><br />'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/159381-solved-foreach-array/#findComment-840685 Share on other sites More sharing options...
Bifter Posted May 23, 2009 Author Share Posted May 23, 2009 I guess that would of helped - thanks - I am learning!!!! Quote Link to comment https://forums.phpfreaks.com/topic/159381-solved-foreach-array/#findComment-840687 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.