1

Here i am having one array, using this array i have to get the index like which having null or empty values,i goggled it but i am not getting my expected answer,kindly see below i have posted my expected answer.

print_r($val);

    Array
(
    [id] => 4 A
    [tripID] => 
    [startFrom] => 1
    [limit] => 20
    [cabID] => 
)

Expected answer

  1. tripID
  2. cabID
  • Do you select data from database?Give us the code and query and loops. I'm afraid I can't help you with just a printed array because the printed array is just the result of problem not the problem itself. – Mobin F.R.G Jul 18 '18 at 05:20
  • I'm not sure the sample array is valid. You are missing the comma at the end of each line. – CharlesEF Jul 18 '18 at 05:24
  • Possible duplicate of [Remove empty array elements](https://stackoverflow.com/questions/3654295/remove-empty-array-elements) – Keval Domadia Jul 18 '18 at 05:33

2 Answers2

2

This should help -

$a = array
(
    'ID' => '4 A',
    'tripID' => '',
    'startFrom' => 1,
    'limit' => 20,
    'cabID' => '',
);
// Filter array if value is  blank or null but not 0
$check = array_filter($a, function($v) {
  return $v == '' || $v == null;
});
// Extract the keys
print_r(array_keys($check));

Output

Array
(
    [0] => tripID
    [1] => cabID
)

array_filter()

Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
0

This function should put you in the right direction array_filter. Seems like a homeworkey question, mind.

Joshua
  • 1,128
  • 3
  • 17
  • 31