开发者

echo an element of an array in php/json

开发者 https://www.devze.com 2023-04-04 03:15 出处:网络
array: [\"author\"]=> array(1) { [0] => array(2) { [\"name\"]=> array(1) { [\"$t\"]=> string(10) \"CALLOFDUTY\"

array:

["author"]=> array(1) { 
    [0] => array(2) { 
        ["name"]=> array(1) {
            ["$t"]=> string(10) "CALLOFDUTY" 
        }}}

my code (not working) :

$entry["author"]["0"]["name"]["$t"]

Do you find any开发者_开发问答 errors in the php code above ? whats wrong ? :S


You should use single quotation marks to circumvent problems. Also, you should make sure you use the correct key type - integer 0 is not the same as a character "0".

$entry['author'][0]['name']['$t']

should do the trick.


$ is a special character inside double quotes, if you want to use it as a character you need to escape it: \$, or use single quotes instead.

As it is your code is looking for an array element with an index whose value is in a variable called $t


Try this one:

$entry["author"][0]["name"]['$t']
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号