Re: Array Question

From: Date: Wed, 29 Mar 2006 16:10:40 +0000
Subject: Re: Array Question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-232833@lists.php.net to get a copy of this message
cybermalandro cybermalandro wrote:
So, I have an array that looks like this rray(3) { [0]=> array(8) {
    ["line"]=>
    string(1) "1"
    ["ponbr"]=>
    string(5) "34474"
    ["emt"]=>
    string(3) "yes"
    ["qty"]=>
    string(1) "5"
    ["price"]=>
    string(2) "19"
    ["shipdate"]=>
    string(8) "11/06/07"
    ["tracking"]=>
    string(17) "11111111111111111"
    ["approved"]=>
    string(4) "true"
} [1]=> array(8) {
    ["line"]=>
    string(1) "1"
    ["ponbr"]=>
    string(5) "TEST1"
    ["emt"]=>
    string(3) "yes"
    ["qty"]=>
    string(1) "5"
    ["price"]=>
    string(2) "19"
    ["shipdate"]=>
    string(8) "12/04/06"
    ["tracking"]=>
    string(9) "123123123"
    ["approved"]=>
    string(4) "true"
} [2]=> array(8) {
    ["line"]=>
    string(1) "2"
    ["ponbr"]=>
    string(5) "TEST1"
    ["emt"]=>
    string(3) "yes"
    ["qty"]=>
    string(1) "5"
    ["price"]=>
    string(2) "12"
    ["shipdate"]=>
    string(8) "12/04/06"
    ["tracking"]=>
    string(12) "123123123123"
    ["approved"]=>
    string(4) "true"
} } I want to see if the array["ponbr"] values matched then pick this array and construct another one with the matched arrays so I can get something like this [0]=> array(8) {
    ["line"]=>
    string(1) "1"
    ["ponbr"]=>
    string(5) "TEST1"
    ["emt"]=>
    string(3) "yes"
    ["qty"]=>
    string(1) "5"
    ["price"]=>
    string(2) "19"
    ["shipdate"]=>
    string(8) "12/04/06"
    ["tracking"]=>
    string(9) "123123123"
    ["approved"]=>
    string(4) "true"
} [1]=> array(8) {
    ["line"]=>
    string(1) "2"
    ["ponbr"]=>
    string(5) "TEST1"
    ["emt"]=>
    string(3) "yes"
    ["qty"]=>
    string(1) "5"
    ["price"]=>
    string(2) "12"
    ["shipdate"]=>
    string(8) "12/04/06"
    ["tracking"]=>
    string(12) "123123123123"
    ["approved"]=>
    string(4) "true"
} What is the best way to do this efficiently? Thanks for your input! $resultArray = array();
foreach($array as $key=>$val) { if($val['ponbr'] === 'TEST1') { $resultArray[$key] = $val; } } $resultArray will contain the output you specified; pretty quick IMO. - tul

« previous php.general (#232833) next »