samedi 18 mai 2019

how to check if array is null ? else continue via foreach- loop

I need to get foreach loop inside if-else loop.

if-loop, checks if company -> address element is null or not

   (!isnull ($company->addresses ))

if not then foreach should extract JSON elemnts to objects.

1) looks like it stop going thru loops because foreach loop is inside If-loop.

 if (!isnull ($company->addresses )) {

     foreach ($company->addresses as $Addr) {
         $city = $Addr->city;
         $postcode = $Addr->postCode;
         $street = $Addr->street;
         $careOf = $Addr->careOf;
    } else
      {   return false;}

1) ideas, how solve this? 2) how to improve this code ?

Aucun commentaire:

Enregistrer un commentaire