desithugg Posted March 24, 2007 Share Posted March 24, 2007 <? $battle['move_1'] = "water"; $battle['move_2'] = "fire"; $battle['move_3'] = "thunder"; $battle['move_4'] = "rock"; ?> Now I want to check which array key has the array value fire or anything...is that possiable? Link to comment https://forums.phpfreaks.com/topic/44151-php-arrays/ Share on other sites More sharing options...
Lumio Posted March 24, 2007 Share Posted March 24, 2007 <?php $i = ''; foreach($battle as $index => $s) { if ($s == 'fire') { $i = $index; break; } } ?> Link to comment https://forums.phpfreaks.com/topic/44151-php-arrays/#findComment-214375 Share on other sites More sharing options...
Barand Posted March 24, 2007 Share Posted March 24, 2007 array_search() Link to comment https://forums.phpfreaks.com/topic/44151-php-arrays/#findComment-214376 Share on other sites More sharing options...
suzzane2020 Posted March 24, 2007 Share Posted March 24, 2007 foreach($battle as $key=>$value) { echo $key . " =>" .$value; } Link to comment https://forums.phpfreaks.com/topic/44151-php-arrays/#findComment-214378 Share on other sites More sharing options...
desithugg Posted March 24, 2007 Author Share Posted March 24, 2007 kk I got it thanks guys one more thing Link to comment https://forums.phpfreaks.com/topic/44151-php-arrays/#findComment-214396 Share on other sites More sharing options...
ted_chou12 Posted March 24, 2007 Share Posted March 24, 2007 array_search() isnt the array function array_keys()? Ted Link to comment https://forums.phpfreaks.com/topic/44151-php-arrays/#findComment-214401 Share on other sites More sharing options...
desithugg Posted March 24, 2007 Author Share Posted March 24, 2007 array_search() isnt the array function array_keys()? Ted yup but the fallowing worked for me <?php $array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red'); $key = array_search('green', $array); // $key = 2; $key = array_search('red', $array); // $key = 1; ?> soo i did <? $battle['move_1'] = "water"; $battle['move_2'] = "fire"; $battle['move_3'] = "thunder"; $battle['move_4'] = "rock"; $key = array_search('fire', $battle); // $key = move_2; ?> Link to comment https://forums.phpfreaks.com/topic/44151-php-arrays/#findComment-214403 Share on other sites More sharing options...
ted_chou12 Posted March 24, 2007 Share Posted March 24, 2007 ok Link to comment https://forums.phpfreaks.com/topic/44151-php-arrays/#findComment-214404 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.