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? Quote Link to comment 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']; } } Quote Link to comment 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>"; } Quote Link to comment 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"; } Quote Link to comment Share on other sites More sharing options...
nadeemshafi9 Posted February 29, 2008 Share Posted February 29, 2008 do { } while(); or do while(){}; 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.