3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php #$str = 'doom2:'; #var_dump(implode(':',explode(':',$str))); exit; $arr = array('var'=> array('sub2' => 'notouch')); function strAssign(&$arr,$str,$val,$trail=true){ if(!empty($str)){ $str = explode(':',$str); $key = array_shift($str); if((isset($arr[$key]) && gettype($arr[$key])!='array') || !isset($arr[$key])){ $arr[$key] = array(); } strAssign($arr[$key],implode(':',$str),$val); }else{ if($trail){ $arr[] = $val; }else{ $arr = $val; } } } function strFetch(&$arr,$str){ if(!empty($str)){ $str = explode(':',$str); $key = array_shift($str); return strFetch($arr[$key],implode(':',$str)); }else{ return $arr; } } #strAssign($arr,'var:sub:sub2:','value'); #var_dump(strFetch($arr,'var:sub2')); print_r(true);
based on Zn1Ia
Output for 4.3.0 - 7.2.0
1