• Estou tendo um problema para verificar se um índice de um array existe em um índice de um termo da taxonomia.
    Estava tentando fazer isso verificando se o índice “nome” é igual ao índice “name” do objeto ($array[$i][“nome”] == $tax_terms[$i][“name”].
    Porém como a fun??o get_terms retorna um array com WP_Terms (objetos) dentro dela, n?o consigo verificar se o $array[nome] está dentro do $tax_terms.
    Já tentei transformar o objeto de terms em array, mas sem sucesso (usando o (array) na frente).

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Object property names always exist, it is only a question of if it has a value assigned or not. There is no equivalent in objects for what you want to do for arrays. Usually the only reason for using array_key_exists() is to prevent warnings from being logged when trying to use an array key name. This will not happen with object property names.

    Why would you wish to check if an object property name exists? If you are passed an instance of an object, the property exists, assuming it is part of the class declaration.

    Thread Starter Gabriel Henrique

    (@gabrielhenrique)

    @bcworkz,
    I want to check if an object property name exists because I need to transform array entries into new object entries. So I check if it already exists by name.

    Moderator bcworkz

    (@bcworkz)

    You want to transform array data into an already declared class object property? You can check if a class property exists with property_exists(), but you would typically know before hand whether a class has a particular property or not.

    If you are defining or extending your own class, you could include a generic data container property and define the __set() magic method to dynamically save undeclared properties that may exist in the source array but are not defined in your class. See
    https://www.php.net/manual/pt_BR/language.oop5.overloading.php

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Verificar se um índice de um array existe em um índice de um termo da taxonomia’ is closed to new replies.