@ 2020-06-10T00:39:48Z <?php
$json = '[
{"title":"The Call of the Wild","author":"Jack London"},
{"title":"Great Expectations","author":"Charles Dickens"},
{"title":"The Voyage of the Beatle","author":"Charles Darwin"}
]';
$array = json_decode($json, true);
function searchArrayKeyVal($search, $array) {
$results = array();
// search for string in each column
foreach ($array as $idx => $obj) {
foreach ($obj as $key => $value) {
if (stripos($value, $search) !== false) {
array_push($results, $obj);
break;
}
}
}
return $results;
}
print_r(searchArrayKeyVal('charles', $array));
print_r(searchArrayKeyVal('wild', $array));
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.2.0 - 7.2.34 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.33 , 8.2.0 - 8.2.29 , 8.3.0 - 8.3.26 , 8.4.1 - 8.4.13 Array
(
[0] => Array
(
[title] => Great Expectations
[author] => Charles Dickens
)
[1] => Array
(
[title] => The Voyage of the Beatle
[author] => Charles Darwin
)
)
Array
(
[0] => Array
(
[title] => The Call of the Wild
[author] => Jack London
)
)
preferences:dark mode live preview ace vim emacs key bindings
47.31 ms | 408 KiB | 5 Q