Php 访问数组返回类型时出现问题
我试图通过从另一个脚本调用数组值来访问它们 我从我的Php 访问数组返回类型时出现问题,php,Php,我试图通过从另一个脚本调用数组值来访问它们 我从我的countryConfig.xml文件构造了一个数组变量转储确认已成功添加值 countryConfig.php <?php $configFile = 'countryConfig.xml'; function getCountryConfig($configFile) { $xml = new SimpleXmlElement(file_get_contents("countryConfig.xml")); $c
countryConfig.xml
文件构造了一个数组<代码>变量转储确认已成功添加值
countryConfig.php
<?php
$configFile = 'countryConfig.xml';
function getCountryConfig($configFile) {
$xml = new SimpleXmlElement(file_get_contents("countryConfig.xml"));
$countries = array();
$countryId = (string)($xml->city[0]->id);
array_push($countries, $countryId);
$countryId = (string)($xml->city[1]->id);
array_push($countries, $countryId);
// var_dump($countries);
return array (
$countryId[0],
$countryId[1]
);
}
?>
index.php
<?php
require 'includes/countryConfig.php';
$pageContent = 'The countries are' . $countryId[0] . ' and ' . $countryId[1];
?>
不显示任何结果。知道我哪里出错了吗?我打算把国家打印出来 第二个代码块应该类似于:
<?php
require 'includes/countryConfig.php';
$countryId = getCountryConfig('countryConfig.xml');
$pageContent = 'The countries are ' . $countryId[0] . ' and ' . $countryId[1];
echo $pageContent;
您的第二个代码块应该类似于:
<?php
require 'includes/countryConfig.php';
$countryId = getCountryConfig('countryConfig.xml');
$pageContent = 'The countries are ' . $countryId[0] . ' and ' . $countryId[1];
echo $pageContent;
返回数组($cities[0],$cities[1])代码>返回数组…?代码中没有$cities
变量<代码>返回数组($countries[0],$countries[1])
在您的示例中与返回$countries
相同,请原谅$cities
打字错误。仍然返回数组,数组使用返回$countries
。只需打印索引0处的值,然后打印索引1。使用上面和下面的返回数组($cities[0],$cities[1])代码>返回数组…?代码中没有$cities
变量<代码>返回数组($countries[0],$countries[1])
在您的示例中与返回$countries
相同,请原谅$cities
打字错误。仍然返回数组,数组使用返回$countries
。只需打印索引0处的值,然后打印索引1。