Ninjakreborn Posted February 29, 2008 Share Posted February 29, 2008 I have always wondered how to do this. Array Products [414] [525] [3] [test1] [test2] [test3] [223] assume each one has a giant subarray of whatever foreach ($products as &$k) { $products['test1'] = 'yes'; $products['test3'] = 'no'; if (is_numeric($k) { } } In this situation how can I tell what "k" is set to since I need to access for example $products['223']['subkey'] Then how would I know which number I was currently at? Link to comment https://forums.phpfreaks.com/topic/93709-looping-arrays/ Share on other sites More sharing options...
rhodesa Posted February 29, 2008 Share Posted February 29, 2008 foreach ($products as $key => $item) { if(is_numeric($key)){ echo $item['subkey']; } } Link to comment https://forums.phpfreaks.com/topic/93709-looping-arrays/#findComment-480140 Share on other sites More sharing options...
tinker Posted February 29, 2008 Share Posted February 29, 2008 while (list($k, $v) = each($a)) { echo $k.": ".$v."<br>"; } and a way which puts the pointer back at the begining foreach ($a as $k => $v) { echo $k.": ".$v."<br>"; } Link to comment https://forums.phpfreaks.com/topic/93709-looping-arrays/#findComment-480141 Share on other sites More sharing options...
nadeemshafi9 Posted February 29, 2008 Share Posted February 29, 2008 AND $array[1]["man"]["head"]="big"; $array[1]["man"]["ear"]="small"; $array[1]["man"]["muchtash"]="gay"; $array[2]["man"]["head"]="big"; $array[2]["man"]["ear"]="small"; $array[2]["man"]["muchtash"]="lazered"; for($i=0;$i<count($array);$i++){ echo $array[$i]["man"]["head"]="big"; $array[$i]["man"]["ear"]="small"; $array[$i]["man"]["muchtash"]="lazered"; } Link to comment https://forums.phpfreaks.com/topic/93709-looping-arrays/#findComment-480155 Share on other sites More sharing options...
nadeemshafi9 Posted February 29, 2008 Share Posted February 29, 2008 do { } while(); or do while(){}; Link to comment https://forums.phpfreaks.com/topic/93709-looping-arrays/#findComment-480157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.