Cakephp check to see if two values are in array


Cakephp check to see if two values are in array



I need to only allow members to write a review on a accommodation if they have stayed at the accommodation and there member_id matches the Auth->user('id').

On the accommodation/view I pass the BookingRequests data.

which looks like this

BookingRequest   0     member_id => 4     accepted => 1   1     member_id => 5     accepted => 0   2     member_id => 4     accepted => 0 

How would I search the array so I can allow only people who have stayed to add a review?




How to get the PHP Version?

1:



PHP - header(“Location:”) inside a function redirects without calling function
It's not as easy in PHP in other languages so you have to inject in a different way.


Access field in a many-to-many intermediate table with DQL in Doctrine
.
Automatic documentation from PHP code
Something like this:.
Troubleshooting unexpected T_PUBLIC error [closed]
$vars = array(); foreach ($members as $request) {   if ($request->accepted) {     array_push($vars, $request);   } } 


spl_autoload fails when script ran from command line


PHP Memory Optimization

2:



How many deep can PHP include go
Try this, .
function search($array, $key, $value)     {         $results = array();          if (is_array($array))         {             if ($array[$key] == $value)                 $results[] = $array;              foreach ($array as $subarray)                 $results = array_merge($results, search($subarray, $key, $value));         }          return $results;     }      $array = array(                   "member_id" => 4, array("accepted" => 11),                   "member_id" => 5, array("accepted" => 02),                    "member_id" => 4, array("accepted" => 0)                    );       $stayedmember = search($array,$memberID,"accepted");      print_r($stayedmember ); 


3:


Assuming 'accepted' determines if they have stayed at the accommodation or not and the below test array is indeed the format of your data array, then you could use the following code:.
/* Test data */ $BookingRequestData = array(     array('member_id' => 4, 'accepted' => 1),     array('member_id' => 5, 'accepted' => 0),     array('member_id' => 4, 'accepted' => 0) );  $canAddReview = (count(Set::extract("/data[member_id=" . 

$this->Auth->user('id') .

"][accepted=1]", array('data' => $BookingRequestData))) > 0);



72 out of 100 based on 52 user ratings 402 reviews