3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '[ { "type": "youtube" }, { "type": "Picture" }, { "type": "Gallery" } ]'; $arr = json_decode($str, true); $type = array_column($arr, 'type'); $key = array_search('youtube', $type); if($key === false){ $key = array_search('Picture', $type); } Var_dump($key);

preferences:
33.44 ms | 407 KiB | 5 Q