array_filter in array inside Simplexml object

Asked

Viewed 75 times

2

I have the following object:

object(SimpleXMLElement)#2 (1) {
["cinema"]=>
  array(82) {
[0]=>
object(SimpleXMLElement)#4 (11) {
  ["@attributes"]=>
  array(2) {
    ["id"]=>
    string(3) "716"
    ["grupo-economico"]=>
    string(8) "Cinemark"
  }
  ["nome"]=>
  string(10) "Aricanduva"
  ["nome-amigavel"]=>
  string(10) "aricanduva"
  ["venda-internet"]=>
  string(5) "false"
  ["endereco"]=>
  object(SimpleXMLElement)#86 (1) {
    ["@attributes"]=>
    array(2) {
      ["latitude"]=>
      string(9) "-23.56582"
      ["longitude"]=>
      string(9) "-46.50364"
    }
  }
  ["precos"]=>
  object(SimpleXMLElement)#87 (0) {
  }
...

I’m trying to access the array ["cinema"] to use it in array_filter but when accessing it I only receive NULL.

$xml->complexos // Retorna a estrutura acima
$xml->complexos["cinema"] // NULL
$xml->complexos->cinema // Retorna apenas o primeiro elemento do array

** Important: I know it works with foreach but I need to use the array_filter to make the code as simple and readable as possible.

  • good morning! You have tried to convert this object into an array?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.