zoukankan      html  css  js  c++  java
  • 字符串数组转为PHP级数组

    先要把字符串处理一下,成为php定义数组的形式,再用eval执行:

    $str="
    Array
    (
    [15] => Array
    (
    [id] => 2304
    [fromtype] => item
    )
    [16] => Array
    (
    [id] => 2313
    [fromtype] => item
    )
    [17] => Array
    (
    [id] => 4265
    [fromtype] => item
    )
    )";

    $str=preg_replace('/[([a-z]+)]s*=>s*([0-9a-z]+)/',"'$1'=>'$2',",$str);
    $p=array('Array','[',']',' )');
    $to=array('array',"'","'",'),');
    $str=str_replace($p,$to,$str);
    //echo $str;

    eval("$arr = ".$str.'; ');
    print_r($arr[15]);

  • 相关阅读:
    poj 2251
    poj 1321
    poj 2777
    poj 3468
    poj 2318
    javascript
    buhui
    swift 构造器
    mac上不了网
    字体
  • 原文地址:https://www.cnblogs.com/lgms2008/p/5047974.html
Copyright © 2011-2022 走看看