PHP: check if object/array is a reference

后端 未结 5 1977

Sorry to ask, its late and I can\'t figure a way to do it... anyone can help?

$users = array(
    array(
        \"name\" => \"John\",
        \"age\"   =         


        
5条回答
  •  隐瞒了意图╮
    2020-12-17 16:04

    if you want to get rid of recursive elements:

    a=3; $arr->b=&$arr;
    //$arr=array('a'=>3, 'b'=>&$arr);
    print_r($arr);
    
    $arr_clean=eval('return '.strtr(var_export($arr, true), array('stdClass::__set_state'=>'(object)')).';');
    print_r($arr_clean);
    ?>
    

    output:

    stdClass Object ( [a] => 3 [b] => stdClass Object *RECURSION* ) 
    stdClass Object ( [a] => 3 [b] => ) 
    

提交回复
热议问题