gpt4 book ai didi

PHP:从数组中选择 child

转载 作者:行者123 更新时间:2023-12-02 07:07:03 24 4
gpt4 key购买 nike

$array = array(
array(
'key1',
'text 1 text 1 text 1'
),

array(
'key2',
'text 2 text 2 text 2'
),

array(
'key3',
'text 3 text 3 text 3'
)
);

对不起标题,没有例子很难解释。

用户想要阅读一些文本。例如,key2 的文本。所以当输入是key2时,我想显示文本:text 2 text 2 text 2

但是我如何使用 PHP 选择该文本?

最佳答案

如果可以的话,我认为使用键作为数组中的实际键:

$array = array("key1" => "text 1 text 1",
"key2" => "text 2 text 2",
"key3" => "text 3 text 3");

//now use this:
echo $array["key2"];

如果你不能操作数组,你可以使用循环创建一个数组,如上所述:

$newArray = array();
foreach($array as $sub){
$newArray[$sub[0]] = $sub[1];
}

这仅在您确定键始终是第一个元素而文本始终是第二个元素时才有效。

关于PHP:从数组中选择 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10063774/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com