Home  >  Article  >  Backend Development  >  Can PHP Object Arrays Be Used with array_column?

Can PHP Object Arrays Be Used with array_column?

Susan Sarandon
Susan SarandonOriginal
2024-10-24 11:55:29282browse

Can PHP Object Arrays Be Used with array_column?

PHP: Using array_column with an Array of Objects

Question:

Can array_column be utilized with an array of objects? Despite implementing the ArrayAccess interface, it appears to be ineffective. Is there a need to implement another interface?

Answer:

Yes, it is possible to use array_column with an array of objects. However, PHP 5 requires a different approach compared to PHP 7.

PHP 5:

In PHP 5, array_column does not support arrays of objects. Instead, use array_map:

<code class="php">$titles = array_map(function($e) {</code>

The above is the detailed content of Can PHP Object Arrays Be Used with array_column?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn