如何在PHP中访问此数组的不同部分?

时间:2015-11-01 20:53:10

标签: php arrays

我使用网站API来检查某些链接的状态,它会使用json返回状态,因此我使用$obj->result->acQeh1UXI-c->status来访问它,工作正常。

如何获取每个文件的状态,我尝试print_r($obj);,但我猜错了,因为它没有显示任何内容

如果我使用stdClass Object ( [status] => 200 [msg] => OK [result] => stdClass Object ( [acQeh1UXI-c] => stdClass Object ( [id] => acQeh1UXI-c [status] => 200 [name] => 2769.rar [size] => 18693570 [sha1] => 739c79942bf743b35223fc59e693fcfffc8c8433 [content_type] => application/x-rar [cstatus] => 0 ) [BNdoJQDSSFo] => stdClass Object ( [id] => BNdoJQDSSFo [status] => 200 [name] => 2589.rar [size] => 99478 [sha1] => 56427728d57c0bd611018305a9133eac83ef8a3a [content_type] => application/x-rar [cstatus] => 0 ) [OrnGndPlQEI] => stdClass Object ( [id] => OrnGndPlQEI [status] => 200 [name] => 1234.rar [size] => 293646 [sha1] => 746e09cfaeef4c9c1e6abb7205e78615e661f21b [content_type] => application/x-rar [cstatus] => 0 ) ) ) 我会得到以下内容:

namespace ConsoleApplication2
{
  class Program
  {
    static void Main()
    {
        Console.WriteLine("Welcome to our Multiplex");



        Console.WriteLine("We are presently Showing:");
        Console.WriteLine("1.Legend");
        Console.WriteLine("2.Macbeth");
        Console.WriteLine("3.Everest");
        Console.WriteLine("4.A Walk In the Woods");
        Console.WriteLine("5.Hotel Transylvania");

        Console.WriteLine("Enter the number of the film you wish to see?");

        {


            string moviestring = Console.ReadLine();

            int movie = int.Parse(moviestring);

2 个答案:

答案 0 :(得分:2)

我建议您使用<td><%= link_to "Favorite", create_favorite_path(current_user.id, res.id), method: :post, :remote => true %></td> 中提供的第二个参数转入关联数组。

import XCPlayground

XCPlaygroundPage.currentPage.needsIndefiniteExecution = true

import Foundation

class C {
    var txt: String = "start"
    init(group: dispatch_group_t) {
        dispatch_group_enter(group)
        print(txt)
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { () -> Void in
            usleep(200000)
            self.txt = "end"
            print(self.txt)
            dispatch_group_leave(group)
        }
    }
}

func f() {
    let group = dispatch_group_create()
    let c = C(group: group)
    dispatch_group_notify(group, dispatch_get_main_queue()) { () -> Void in
        print("notify: \(c) created")
    }
}

f()
print("continue running ...")

然后你可以,

json_decode

答案 1 :(得分:0)

尝试用支架?

$obj['result']['acQeh1UXI-c']['status']