1

I have the below array coming though, ideally I am looking for a way of matching one value and printing out another value.

e.g.

if($randomvalue  == $cards[Card][unit_id]) { echo $cards[SaleDetail][date_pid_signed]; }

I'm not sure exactly how to go about getting the above to work with the current array structure as below.

Any ideas how I can get around this?

Thanks

$cards = Array
(
[0] => Array
    (
        [Card] => Array
            (
                [id] => 210
                [property_id] => 4
                [unit_id] => 90
            )

        [SaleDetail] => Array
            (
                [property_agent] => 
                [date_pid_signed] => 2012-06-15
                [property_date_listed] => 
            )

    )

[1] => Array
    (
        [Card] => Array
            (
                [id] => 209
                [property_id] => 4
                [unit_id] => 103
            )

        [SaleDetail] => Array
            (
                [property_agent] => 
                [date_pid_signed] => 2011-10-21
                [property_date_listed] => 
            )

    )

)

3 Answers 3

1
foreach($cards as $card){
    if($randomvalue  == $card[Card][unit_id]) { 
       echo $card[SaleDetail][date_pid_signed]; 
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

Use $cards[0]['Card']['unit_id'] and $cards[0]['SaleDetail']['date_pid_signed']. Notice the indexes [0]. You can then use [1].

You might also want to check foreach or for loops!

2 Comments

Thanks however how do I do it for any of the arrays. i.e. the [0] goes up to 100 + (or more), above was just an example snippit. Ideally I need it to be something like $cards[$X]['Card']['unit_id']
i mentioned about foreach or for loops.
0
if($randomvalue  == $cards[0][Card][unit_id]) { echo $cards[0][SaleDetail][date_pid_signed]; }

also you can do

foreach($cards as $card)
{
    if($randomvalue  == $card[Card][unit_id]) 
    { 
       echo $card[SaleDetail][date_pid_signed]; 
     }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.