3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( 'fruits' => [ 'apple' => 'value', 'orange' => 'value' ], 'vegetables' => [ 'onion' => 'value', 'carrot' => 'value' ]); $string = 'fruits[orange]'; $indexes = (preg_split( "/(\[|\])/", $string)); $first_index= $indexes[0]; $seconnd_index= $indexes[1]; if(isset($array[$first_index][$seconnd_index])) { echo "exist"; } else { echo "not exist"; }

preferences:
27.98 ms | 404 KiB | 5 Q