[PHP-NOTES] note 130178 added to function.str-contains

[email protected] ("[email protected]")
Newsgroups php.notes
Message-ID <[email protected]>
<?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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.