-2
Array
(
    [leadAssignType] => 3
    [ratio] => Array
        (
            [0] => Array
                (
                    [assigned_to] => 12 
                    [ratio] => 5
                )

            [1] => Array
                (
                    [assigned_to] => 13 
                    [ratio] => 3
                )

        )

)

Hello all ! I am struck in one problem. This is my array getting after form submit and I just want to check whether key assigned_to is present for at least once. If it is not present then it should show error message. How can I do that?

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Bhinal Chauhan
  • 251
  • 3
  • 11
  • already answered in https://stackoverflow.com/questions/19420715/check-if-specific-array-key-exists-in-multidimensional-array-php – caryarit ferrer Jul 21 '17 at 12:08
  • Please do a search before posting, SO has already 2 questions like that : https://stackoverflow.com/a/6990868/5847906 and https://stackoverflow.com/a/19421079/5847906 – Ayak973 Jul 21 '17 at 12:09

1 Answers1

2

simple use array_column to get the specific column from multidimensional array . if the count of array is more than zero key exists otherwise key not exists so show the error message .

if(count(array_column($array['ratio'],'assigned_to'))>0){

  echo "key exist in the multi-dimensional array";

}else{

   echo "key not present ";   
}
JYoThI
  • 11,977
  • 1
  • 11
  • 26