I am asking Similar question compare request values to array – it doesn’t work to me, my scenario is totally different
$mkt = array(
array(
'title' => "Photos",
'iconlink' => "http://example.com/xyz.png",
'pkg' => 'test'
),
array(
'title' => "code",
'iconlink' => "http://example.com/xyz.png",
'pkg' => 'main'
),
array(
'title' => "code",
'iconlink' => "http://example.com/xyz.png",
'pkg' => 'main'
));
I am having logic issue in this problem, problem is i am getting value via $_REQUEST variable and then i compare this request value to array pkg element. If comparison is true then i want to get another elements except to matched one. In this as suggested, i am using unset to remove the key of element which is matched and all array point to new variable, it working but not for first element of array, it shows null when i compare request variable to first element of array:
$mkt = array();
$newArray = $mkt;
foreach ($newArray as $key => $value ) {
if (in_array($pn, $mkt, true)) {
unset($newArray[$key]);
}
}
$rand_ad = array_rand( $newArray, 1 );
echo json_encode( $newArray[$rand_ad] );
Please have a look on this issue very grateful to me.
Loop in each value, if
$pnis equal with that loop’spkgthen unset thanunsetthat element: