There is a code that receives from the VC long pool the corresponding data in JSON. After json_decode we get an array: (Here is its print_r)

stdClass Object ([ts] => 1843599983 [updates] => Array ([0] => Array ([0] => 9 [1] => -142578342 [2] => 0) [1] => Array ( [0] => 7 [1] => 277292865 [2] => 537091) [2] => Array ([0] => 4 [1] => 537092 [2] => 1 [3] => 277292865 [4] => 1491849931 [5] => ... [6] => Olooop [7] => stdClass Object ()) [3] => Array ([0] => 80 [1] => 1 [ 2] => 0)))

How to find a specific value in a nested array without knowing its exact address?

Here is the code:

$ts = mysql_fetch_assoc(mysql_query("SELECT `var` FROM `settings` WHERE `settings`.`id` = 3 LIMIT 1" )); $ts = $ts['var']; $kek = json_decode(file_get_contents('https://newimv4.vk.com/nim0304?act=a_check&key=35175cb798dae0fa77671dcf0bce35e7efb30&ts='.$ts.'&wait=90&mode=2&version=1')); $ts = $kek -> ts; mysql_query("UPDATE `settings` SET `var` = '".$ts."' WHERE `settings`.`id` = 3;") or die("Ошибка " . mysqli_error()); print_r($kek); $num = array_search('4',($kek->updates)); print_r($num); 

array_search does not find anything, despite the fact that this value is there. Help)

  • Well, first add the second parameter true and output - Naumov
  • @Naumov is possible in more detail? - Darlanar
  • mysql_* Warning This extension is outdated since PHP 5.5.0 and removed in PHP 7.0.0. Use MySQLi or PDO_MySQL instead. See also the MySQL instruction: API selection and the corresponding FAQ for more details. php.net/manual/ru/function.mysql-query.php - E_p
  • @Naumov why true? What objects did not please you? - Lexx918

1 answer 1

array_search cannot search recursively in a multidimensional array, it searches only in the first row of values. For recursive search in the examples for the array_search function in the official dock there is a good example: http://php.net/manual/ru/function.array-search.php#91365

  • stdClass Object ( see the question in the output dump is an array of yours? - Naumov
  • one
    You are looking for the $ kek-> updates property, and it is an array - isn't it? If you want everything to be an array, then use @Darlanar's advice and specify the second parameter as true in json_decode. For more information, see the documentation - Alexander Oleynikov