Home > Software design >  How to extract value from COUNT array within array
How to extract value from COUNT array within array

Time:08-20

How to extract only value from the below array

Array ( [COUNT(department_name)] => 3 )

this is a response from a db query the actual value came like this

Array ( [0] => Array ( [COUNT(department_name)] => 3 ) )

if we select the 0th index $department[0] it is giving this

 Array ( [COUNT(department_name)] => 3 )

but now i need only the value from this i.e 3 how can i extract the value from this. and i tried like this $department[0]['department_name'] and $department[0]['COUNT(department_name)'] but no result.

CodePudding user response:

You can use this simply and it's working -

$department = var_export($department,true);
print_R($department[0]['COUNT(department_name)'])

var_export helps you get the structured information of a variable.

For more see this - var_export

NOTE - I will suggest you to to get a more readable key from database.

  • Related