繁体   English   中英

php 具有数组索引值的数组

[英]php array with a index value of an array

我试图让 $adjective 数组有一个来自 $currentCount 的值,但它给了我一个错误。

它说语法错误。 谢谢!

$currentCount = [0, 0, 0, 0, 0, 0];
$adjectives=["a","b","c","d","e"];

echo "<h1> The $adjectives[$currentCount[0]] ";

您应该将字符串和数组变量与索引值分开,因为它将方括号[]作为字符串读取。

$currentCount = [0, 0, 0, 0, 0, 0];
$adjectives = ["a", "b", "c", "d", "e"];

echo "<h1> The " . $adjectives[$currentCount[0]];

您应该使用{}将字符串中的 PHP 部分包装起来。 尝试这个

$currentCount = [0, 0, 0, 0, 0, 0];
$adjectives=["a","b","c","d","e"];

echo "<h1> The {$adjectives[$currentCount[0]]} ";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM