如何在php中的另一个数组中获取数组的值? [英] How to get value of array inside another array in php?

查看:130
本文介绍了如何在php中的另一个数组中获取数组的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个 php 页面,其中我在数组值中获取了数组.

I made a php page in which I got the array within array value.

这是我的数组:

Array (
  [events] => Array ( [0] => 5 [1] => 7 [2] => 8 )
  [fromdate] =>
  [todate] =>
  [description] =>
  [subject] =>
  [fromname] =>
  [replyto] =>
  [senddatetime] =>
  [timezone] => America/Los_Angeles
  [message] =>
  [submit_skip] => Continue
)

这个数组是上一页的 POST 数据.我想在变量中获取 events 值.我怎样才能做到这一点?

This array is the POST data from previous page. I want to get events value in a variable. How can I do this?

我用它来获取事件值,但它给了我数组,但我想获取第一个事件值

I use this for getting events value but it gives me the array but I want to get first event value

echo $eventid=$_POST['events'];

推荐答案

To echo:

echo $_POST['events'][0];

将其分配给变量:

$eventid = $_POST['events'][0];

将数组分配给一个变量并从新数组中获取值:

$events = $_POST['events'];
$eventid = $events[0];

[0] 表示第一个值的键,因为它被设置为 0.

[0] represents the key of the first value since it is set to be 0.

这篇关于如何在php中的另一个数组中获取数组的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆