-2

I have a following array

Array
(
    [0] => Array
        (
            [0] => 
        )

    [1] => Array
        (
            [0] => flatrate
            [1] =>  flatrate3
            [2] =>  freeshipping
        )

    [2] => Array
        (
            [0] => flatrate
            [1] =>  flatrate2
            [2] =>  flatrate3
            [3] =>  flatrate4
            [4] =>  freeshipping
        )

)

Now, i need to match some element in this like

if freeshipping in above array . it should echo yes else no.

Please suggest, how can i do this.

Ranjeet singh
  • 794
  • 1
  • 16
  • 38

3 Answers3

0
for($i = 0; count($array); $i++){
    if(in_array($string, $array[$i]) echo true;
}
Oliver
  • 3,981
  • 2
  • 21
  • 35
0

you can do simple code like that :

 foreach ($array as $key) {
                    foreach ($key as $value) {
                        if($value == "your condition")
                        {
                        echo 'yes';
                        }else{
                            echo 'no';
                        }
                    }   
                }

try it.

MYoussef
  • 144
  • 9
0

Create A function

function checkfreeShipping($arrData)
{
   foreach($arrData as $data){

      if(in_array('freeshipping',$data))
      return true;
   }


}

Call defined function to check Shipping -

if(checkfreeShipping($cartArr)){

  echo "free Shipping";
}
else{
  echo "Paid Shipping";
}
Jitendra Yadav
  • 896
  • 1
  • 6
  • 14