简体   繁体   English

在PHP中获取数组项的单个值

[英]get a single value of array items in php

I have an array in my php code, but I don't know how to get the value of it. 我的php代码中有一个数组,但是我不知道如何获取它的值。

my array : 我的数组:

$year =  array(
    'data' => to_html(strtr(to_lang('main/date_format_other_years'), array(
    '^day' => '',
    '^month' => '',
    '^year' => date('Y', $timestamp),
 ))),
);

I have a variable named $stringyear , how can I set it to 'year' value of this array? 我有一个名为$stringyear的变量,如何将其设置为该数组的'year'值?

您可以按以下方式访问它:

$stringyear = $year[1]['^year'];

这应该起作用: $stringyear = $year['data']['^year'];

It depends on what to_html function returns, If it returns a string (for displaying in html), then you can not get it (You can but you need to parse the string again). 这取决于to_html函数返回什么,如果它返回一个字符串(用于在html中显示),则无法获取它(可以,但是您需要再次解析该字符串)。

Since you have the $timestamp , why not just do with: 由于您有$timestamp ,为什么不这样做:

$stringyear = date('Y', $timestamp);

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

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