Search multidimensional array
To get the the key/index of an array by a nested value combine array_search
and array_column
.
- array_search
- Get key for item in array (aka its index in the array)
- Returns first match
- array_column
- Return array containing all values for a column in an array (aka associative array property)
$fish = array(
0 => array(
'description' => 'A red fish',
'title' => 'Salmon'
),
1 => array(
'description' => 'A whiskered fish',
'title' => 'Catfish'
)
);
$key = array_search($fish, array_column($, 'catfish')); // returns 1
print_r($fish[$key]);
// prints Array( Description] => A whiskered fish [Title] => Catfish )
var_dump to string
Use output buffering
<?php
ob_start();
var_dump($someVar);
$result = ob_get_clean();
?>
PHP operators
truthy OR
$res = $this ?? $that;