使用list()的语法错误 [英] Syntax error using list()
问题描述
我在PHP中使用list功能似乎有语法问题。在下面的代码中,我试图使用一行代码将两个数组值转换为两个单独的变量。我知道这可以用一个简单的变量。我可以在两条单独的线上成功完成 - 按照线路评论工作就好了。
可以somone请协助正确的suntax线: -
list ($ outlying,$ base)=(array($ row ['outlying_price'] ['base_price']));
因此行返回以下错误: -
警告:第19行的C:\ wamp64 \\\test.php中的非法字符串偏移'base_price'
注意:未定义的偏移:C中为1 :第19行:\ wamp64 \\\test.php
我尝试过:
I appear to have a syntax problem using the list feature in PHP. In the code below I am trying to convert two array values into two seperate variables, using one line of code. I know this is possible with a simple variable. I can do it successfully on two seperate lines - as per the lines commented out work just fine.
Can somone please assist with the correct suntax for the line :-
list($outlying, $base) = (array($row['outlying_price'] ['base_price']));
as this line returns the following error:-
Warning: Illegal string offset 'base_price' in C:\wamp64\www\test.php on line 19
Notice: Undefined offset: 1 in C:\wamp64\www\test.php on line 19
What I have tried:
<?php
include 'database.php';
$pdo = Database::connect();
try{
$collhub = "bet";
$delhub = "jnb";
echo $collhub;
echo $delhub;
echo "<br>";
$sql = "SELECT * FROM `new_ice_price_table` WHERE collection_town_code = '$collhub' AND delivery_town_code = '$delhub'";
$result = $pdo->query($sql);
if($result->rowCount() > 0){
//echo "<table class='table table-striped table-bordered sortable'>";
while($row = $result->fetch()){
//print_r($row);
//list($base) = array($row['base_price']);
//list($outlying) = array($row['outlying_price']);
list($outlying, $base) = (array($row['outlying_price'] ['base_price']));
echo "<br>";
echo $base;
echo "<br>";
echo $outlying;
}
echo "</table></br>";
unset($result);
} else{
echo "No records matching your query were found.";
}
} catch(PDOException $e){
die("ERROR: Could not able to execute $sql. " . $e->getMessage());
}
?>
推荐答案
outlying,
base )=(array(
base) = (array(
row ['outlying_price'] ['base_price']));
,因为此行返回以下错误: -
警告:第19行C:\ wamp64 \\\test.php中的非法字符串偏移'base_price'
注意:未定义的偏移量:C中的1:第19行的\ wamp64 \\\\\ test.php
我的尝试:
row['outlying_price'] ['base_price']));
as this line returns the following error:-
Warning: Illegal string offset 'base_price' in C:\wamp64\www\test.php on line 19
Notice: Undefined offset: 1 in C:\wamp64\www\test.php on line 19
What I have tried:
<?php
include 'database.php';
这篇关于使用list()的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!