Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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_Wordpress - Fatal编程技术网

Php 如何访问数组的第一行,然后从中访问键和元素

Php 如何访问数组的第一行,然后从中访问键和元素,php,wordpress,Php,Wordpress,所以我正在研究WordPress+PHP,我使用了WordPress的get_结果和OBJECT_K参数,它返回数组 输出架构看起来像这样(我猜): 我想知道如何只使用currentProducts的第一行,在Python中,我们可以执行类似currentProducts[0]的操作,它返回第一行 我试着用代码来实现它 foreach ( $currentProducts as $page ) { echo '<script>console.log('.$page->w

所以我正在研究WordPress+PHP,我使用了WordPress的get_结果和OBJECT_K参数,它返回数组

输出架构看起来像这样(我猜):

我想知道如何只使用currentProducts的第一行,在Python中,我们可以执行类似currentProducts[0]的操作,它返回第一行

我试着用代码来实现它

foreach ( $currentProducts as $page )
{
    echo '<script>console.log('.$page->wp_reference_id.')</script>';

}
我在寻找类似的东西,但不是运气

$currentProducts[0]->wp_reference_id
$currentProducts[0]->wp_payment_id
应用简单的
foreach()
循环并获得相应的值

foreach($currentProducts as $currentProduct){
   echo '<script>console.log('.$currentProduct->wp_reference_id.')</script>';;
}
示例输出:-

应用简单的
foreach()
循环并获得相应的值

foreach($currentProducts as $currentProduct){
   echo '<script>console.log('.$currentProduct->wp_reference_id.')</script>';;
}

示例输出:-

与其猜测结构,不如尝试类似于
var\u export($currentProducts)的方法查看它包含的内容。显示
var\u export($currentProducts)的值这样你就可以得到一个具体的答案,而不是每个人都在毫无意义地猜测和给出建议查看它包含的内容。显示
var\u export($currentProducts)的值这样你就能得到一个具体的答案,而不是每个人都毫无意义地猜测和给出建议。@anant singh活到死,这正是我想要的!谢谢大家!@SamLee很高兴帮助你:):)快乐编码…:)@anant singh活到死正是我想要的!谢谢大家!@SamLee很高兴帮助你:):)编码快乐…)
foreach($currentProducts as $currentProduct){
   echo '<script>console.log('.$currentProduct->wp_reference_id.')</script>';;
}
$firstArray = current( (Array)$currentProducts );