Search
 
SCRIPT & CODE EXAMPLE
 

PHP

string match in php

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

if (str_contains('Foo Bar Baz', 'Foo')) {
  echo 'Found';
}
Comment

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);
?>
Comment

match php

<?php

$age = 23;

$result = match (true) {
    $age >= 65 => 'senior',
    $age >= 25 => 'adult',
    $age >= 18 => 'young adult',
    default => 'kid',
};

var_dump($result);
?>
Comment

php match

<?php
$return_value = match (subject_expression) {
    single_conditional_expression => return_expression,
    conditional_expression1, conditional_expression2 => return_expression,
};

$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);
?>
Comment

php match expression

echo match ($x) {
    0 => 'Car',
    1 => 'Bus',
    2 => 'Bike',
};
Comment

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('/are/', $a)) {
    echo 'true';
}
Comment

PREVIOUS NEXT
Code Example
Php :: Laravel Retrieve All Session Data 
Php :: php DateTime comparation 
Php :: laravel create new file if not exists 
Php :: php return function result to variable 
Php :: Object of class IlluminateDatabaseEloquentBuilder could not be converted to string 
Php :: wordpress get id from page title 
Php :: php shorten string with dots 
Php :: laravel set appends 
Php :: valdidate laravel if falid 
Php :: php set environment variable 
Php :: laravel cannot add foreign key constraint 
Php :: how to named route resource laravel 
Php :: php match 
Php :: get post info in php 
Php :: laravel break 
Php :: General error: 1390 Prepared statement contains too many placeholders 
Php :: php convert guzzle response to json 
Php :: php http authentication 
Php :: end foreach loop 
Php :: ubuntu 7.2 deleted php 
Php :: how to see php error log 
Php :: wordpress disable block styles 
Php :: php if elseif 
Php :: import local js file laravel 
Php :: upload multiple images in php 
Php :: taxonomy_get_parents drupal 8 
Php :: associate laravel 
Php :: php timezone change 
Php :: excel return integer from date column laravel 
Php :: php currency formator 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =