0

I am a new learner in php. I found that there is a code:

if($x < time()){
     return [false,'error'];
}

The logic or variable is not matter, but I don't understand how [false,'error'] works. Is it a boolean or array or ..... ?

2
  • It returns an array first element Boolean and second element String. But remember that return works on a function.
    – Mehrwarz
    May 3, 2022 at 3:09
  • Thanks for yr response, and I am doing unit test in php. May I ask that is it possible to directly compare an array with an array?
    – littlesam
    May 3, 2022 at 3:23

1 Answer 1

0

It's an array. It has two elements of different two types. The first element type is boolean. The second element is a string.

Arrays can have elements of different types in PHP.

2
  • Thanks for yr response, and I am doing unit test in php. May I ask that is it possible to directly compare an array with an array?
    – littlesam
    May 3, 2022 at 3:16
  • You can compare two arrays with the function array_diff($arr1, $arr2) like: if(array_diff($arr1, $arr2) == []) { ... something you want the code to do if the arrays are equal ... } May 3, 2022 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.