提取数组的元素

时间:2015-06-02 20:56:32

标签: php arrays

假设这个数组:

Array ( [0] => Array ( [id] => 1171 [product_id] => 140 [fileid] => 479717 [purchid] => 847 [cartid] => 833 [uniqueid] => f100c3b3a853202fb6559fbacf025a6aa07f52c7 [downloads] => 99998 [ip_number] => [active] => 1 [datetime] => 2015-06-02 20:10:05 )
    [1] => Array ( [id] => 1172 [product_id] => 140 [fileid] => 313624 [purchid] => 847 [cartid] => 833 [uniqueid] => f00a3c91378ad469f333abeec64753b275f10670 [downloads] => 99999 [ip_number] => [active] => 1 [datetime] => 2015-06-02 20:10:05 )
    [2] => Array ( [id] => 1173 [product_id] => 140 [fileid] => 313618 [purchid] => 847 [cartid] => 833 [uniqueid] => ac125595e2dbca6a086261434582f6e7dfc5638e [downloads] => 99999 [ip_number] => [active] => 1 [datetime] => 2015-06-02 20:10:05 )
    [3] => Array ( [id] => 1174 [product_id] => 140 [fileid] => 313526 [purchid] => 847 [cartid] => 833 [uniqueid] => 3e6123e0a4453de71dec91a177f5b34217625680 [downloads] => 99999 [ip_number] => [active] => 1 [datetime] => 2015-06-02 20:10:05 ))

我想“提取”[0]数组并将其用于其他内容但是必须进行调整。

我说的是0元素,因为它的fileid = 479717是我想要的那个。

所以我正在寻找已提交= $ myvalue的数组(在我的情况下为[0])。我可以将$ myvalue设置为我想要的任何内容。

2 个答案:

答案 0 :(得分:0)

这是否符合您的需求?

function findById($id, $arrayOfArrays){
    foreach ( $arrayOfArrays as $contents ) 
        if ( $contents['id'] == $id ) return $contents;
}

答案 1 :(得分:0)

let threads = 300000;
let requests = 1;

for _x in 0..threads {
    println!("{}", _x);
    let request_clone = request.clone();

    let handle = thread::spawn(move || {
        for _y in 0..requests {
            request_clone.lock().unwrap().push((request::Request::new(request::Request::create_request())));
        }
    });

    child_threads.push(handle);
}