note 130178 added to function.str-contains

From: Date: Thu, 20 Mar 2025 15:52:09 +0000
Subject: note 130178 added to function.str-contains
Groups: php.notes 
Request: Send a blank email to php-notes+get-222010@lists.php.net to get a copy of this message
<?php declare(strict_types=1); $descriptions = [ 'Description One', 'Description Two', 'Description Three', 'Four' ]; // This function filters out the descriptions that contain the word "Description" // and returns an array with only those descriptions, replacing others with null. function formatDescription(array $descriptions): array { return array_map(function ($description) { return str_contains($description, 'Description') ? $description : null; }, $descriptions); } echo '<pre>'; var_dump(formatDescription($descriptions)); echo '</pre>'; ?> // Result array(4) { [0]=> string(15) "Description One" [1]=> string(15) "Description Two" [2]=> string(17) "Description Three" [3]=> NULL } ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 144.178.207.134) ---- Manual Page -- https://php.net/manual/en/function.str-contains.php Edit -- https://main.php.net/note/edit/130178 Del: integrated -- https://main.php.net/note/delete/130178/integrated Del: useless -- https://main.php.net/note/delete/130178/useless Del: bad code -- https://main.php.net/note/delete/130178/bad+code Del: spam -- https://main.php.net/note/delete/130178/spam Del: non-english -- https://main.php.net/note/delete/130178/non-english Del: in docs -- https://main.php.net/note/delete/130178/in+docs Del: other reasons-- https://main.php.net/note/delete/130178 Reject -- https://main.php.net/note/reject/130178 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#222010) next »