7

PHP: Draw the object of a table object according to a criterion of the element o...

 3 years ago
source link: https://www.codesd.com/item/php-draw-the-object-of-a-table-object-according-to-a-criterion-of-the-element-of-object.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

PHP: Draw the object of a table object according to a criterion of the element of object?

advertisements

I have this array of objects. However I want to only pull out the object which meets a certain criteria. If you look at the "post_title" key, I want to only pull out the object if it does not contain a comma. Is this possible?

So in my example below, I want to pull out the array in index 2 as that is the only one that has no comma in the "post_title" key.

Array
(
    [0] => stdClass Object
        (
            [ID] => 504
            [post_title] => Playroom (Black, Custom 2)
        )

    [1] => stdClass Object
        (
            [ID] => 503
            [post_title] => Playroom (Black, Custom 1)

        )

    [2] => stdClass Object
        (
            [ID] => 252
            [post_title] => Play (Black)

        )

)
1

Thank you for looking at this.


Yes you can but you will have to code it yourself, like this:

$results = array();
foreach ($source as $obj) {
  if (strpos($obj->post_title, ',') === false) {
    $results[] = $obj;
  }
}
// $results will now have the elements filtered


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK