Answers for "match expression in php"

PHP
0

php match

<?php
$food = 'cake';

$return_value = match ($food) {
    'apple' => 'This food is an apple',
    'bar' => 'This food is a bar',
    'cake' => 'This food is a cake',
};

var_dump($return_value);
?>
Posted by: Guest on November-03-2021
-2

string match in php

//str_contains ( string $haystack , string $needle ) : bool

if (str_contains('Foo Bar Baz', 'Foo')) {
  echo 'Found';
}
Posted by: Guest on April-18-2021
0

php 8 Match Expression

echo match (8.0) {
  '8.0' => "Oh no!",
  8.0 => "This is what I expected",
};
//> This is what I expected
// TurkoSoft
Posted by: Guest on October-18-2021
-2

string match in php

You could use regular expressions as its better for word matching compared to
strpos, as mentioned by other users. A strpos check for are will also return 
true for strings such as: fare, care, stare, etc. These unintended matches can 
simply be avoided in regular expression by using word boundaries.

A simple match for are could look something like this:

$a = 'How are you?';

if (preg_match('/bareb/', $a)) {
    echo 'true';
}
Posted by: Guest on May-16-2021

Code answers related to "match expression in php"

Browse Popular Code Answers by Language