Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用键获取值时PHP偏移量非法_Php_Arrays - Fatal编程技术网

尝试使用键获取值时PHP偏移量非法

尝试使用键获取值时PHP偏移量非法,php,arrays,Php,Arrays,尝试使用键访问数组的值时,出现非法字符串偏移错误 define('SRV_INFO', array( 'name' => 'Rustafied.com', 'info' => array( 'ip' => '192.223.26.55:26032', 'desc' => '350 slots of pure mayhem' ), 'name' => 'Rustafied.com - Medium',

尝试使用键访问数组的值时,出现非法字符串偏移错误

define('SRV_INFO', array(
    'name' => 'Rustafied.com', 
    'info' => array(
        'ip' => '192.223.26.55:26032',
        'desc' => '350 slots of pure mayhem'
    ),

    'name' => 'Rustafied.com - Medium',
    'info' => array(
        'ip' => '74.91.122.115:28069',
        'desc' => 'The sweet spot between main and low pop'
    )
));

foreach(SRV_INFO as $server) {
                echo '
                <div class="server">
                    <span class="name">'. $server['name'] .'</span>
                    <span class="desc">'. $server['info']['desc'] .'</span>
                    <span class="pop"></span>
                </div>
                ';
            }
define('SRV_INFO',数组(
'name'=>'Rustafied.com',
'info'=>数组(
‘ip’=>‘192.223.26.55:26032’,
“描述”=>“350个纯粹的混乱时段”
),
'name'=>'Rustafied.com-中等',
'info'=>数组(
‘ip’=>‘74.91.122.115:28069’,
'desc'=>'主流行和低流行之间的最佳点'
)
));
foreach(SRV_信息作为$server){
回声'
“.$server['name']”
'.$server['info']['desc'].'
';
}

按照其他代码的编写方式,
定义应该是这样的:

define('SRV_INFO', array(
    array('name' => 'Rustafied.com', 
      'info' => array(
        'ip' => '192.223.26.55:26032',
        'desc' => '350 slots of pure mayhem'
    )),

    array('name' => 'Rustafied.com - Medium',
      'info' => array(
        'ip' => '74.91.122.115:28069',
        'desc' => 'The sweet spot between main and low pop'
    ))
));

如果您对当前代码执行了
var\u dump(SRV\u INFO)
,您会发现SRV\u INFO实际上只是您编写的最后一个条目:

php > var_dump(SRV_INFO);
array(2) {
  ["name"]=>
  string(22) "Rustafied.com - Medium"
  ["info"]=>
  array(2) {
    ["ip"]=>
    string(19) "74.91.122.115:28069"
    ["desc"]=>
    string(39) "The sweet spot between main and low pop"
  }
}

按照编写其余代码的方式,
define
应该是这样的:

define('SRV_INFO', array(
    array('name' => 'Rustafied.com', 
      'info' => array(
        'ip' => '192.223.26.55:26032',
        'desc' => '350 slots of pure mayhem'
    )),

    array('name' => 'Rustafied.com - Medium',
      'info' => array(
        'ip' => '74.91.122.115:28069',
        'desc' => 'The sweet spot between main and low pop'
    ))
));

如果您对当前代码执行了
var\u dump(SRV\u INFO)
,您会发现SRV\u INFO实际上只是您编写的最后一个条目:

php > var_dump(SRV_INFO);
array(2) {
  ["name"]=>
  string(22) "Rustafied.com - Medium"
  ["info"]=>
  array(2) {
    ["ip"]=>
    string(19) "74.91.122.115:28069"
    ["desc"]=>
    string(39) "The sweet spot between main and low pop"
  }
}