0

I am using symfony2.3,

I want to know that How I can get rewardPoints on id bases and which position this id hold in Array between 0 to 4 ?

Like :

I have already got Logged User Id:-

 id = 8; 

In Array I got this :-

Array
(
 [0] => Array
    (
        [rewardPoints] => 790
        [id] => 1
    )

 [1] => Array
    (
        [rewardPoints] => 35
        [id] => 8
    )

 [2] => Array
    (
        [rewardPoints] => 25
        [id] => 14
    )

 [3] => Array
    (
        [rewardPoints] => 10
        [id] => 15
    )

 [4] => Array
    (
        [rewardPoints] => 5
        [id] => 16
    )

)

Sorry for my English.

Thanks.

1 Answer 1

2

Hope this will help you

$counter = 0;
foreach($yourArray as $subArray){
     if($subArray['id'] == 8){         // here set the id what you need
        $position =   $counter;
         $revertPoint = $subArray['rewardPoints']; //here you set the rewardPoints into variable
      }
      $counter++;
}

echo $revertPoint;//result 
echo $position; // position in main array
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for answer. Can you tell me How I can know that id position in Main array ?
Yes, look and try now
Many Thanks This worked,In answer you change if($subArray['id'] == 8 to this if($subArray['id'] == 8). you forget this and echo $position to echo $position; Then I will accept your answer.
Ehh, did!)I was trying to give you fast answer)
thumbs up for you.Thanks.

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.