How to find index of object in php array?

前端 未结 10 1877
时光说笑
时光说笑 2021-02-13 18:46

Here is print_r output of my array:

Array
(
[0] => stdClass Object
    (
        [itemId] => 560639000019
        [name] => Item no1
        [code] =>         


        
10条回答
  •  灰色年华
    2021-02-13 19:38

    In my case, this my array as $array
    I was confused about this problem of my project, but some answer here helped me.

    array(3) { 
               [0]=> float(-0.12459619130796) 
               [1]=> float(-0.64018439966448) 
               [2]=> float(0)
             }
    

    Then use if condition to stop looping

    foreach($array as $key => $val){
               if($key == 0){ //the key is 0
                   echo $key; //find the key
                   echo $val; //get the value
               }
            }
    

提交回复
热议问题