Showing posts with label comparison operators. Show all posts
Showing posts with label comparison operators. Show all posts

Friday, 14 May 2021

Jq: Comparison operators

‘jq’ support comparison operators to process json data.

 

compOperators.json 

{
	"1": {
		"org": [{
			"name": "ABC Cord",
			"yrsOfExperience": 2.2
		}, {
			"name": "XYZ",
			"yrsOfExperience": 1.8
		}],
		"firstName": "Krishna",
		"lastName": "Ram",
		"address": {
			"city": "Bangalore",
			"country": "India"
		}
	},

	"2": {
		"org": [{
			"name": "XYZ",
			"yrsOfExperience": 4.2
		}, {
			"name": "Bokara",
			"yrsOfExperience": 3.8
		}],
		"firstName": "Battu",
		"lastName": "Gopi",
		"address": {
			"city": "Bangalore",
			"country": "India"
		}
	},

	"3": {
		"org": [{
			"name": "Dongle",
			"yrsOfExperience": 2.6
		}, {
			"name": "Binare",
			"yrsOfExperience": 1.11
		}],
		"firstName": "Krishna",
		"lastName": "Ram",
		"address": {
			"city": "Hyderabad",
			"country": "India"
		}
	}

}

Example 1: Get all the employees who are working in Bangalore.

$cat compOperators.json | jq '.[] | select(.address.city=="Bangalore") | .firstName+","+.lastName'
"Krishna,Ram"
"Battu,Gopi"



 

  

Previous                                                    Next                                                    Home

Tuesday, 6 April 2021

Php: Comparison operators

 

Comparison operators used to compare two different values and evaluate the result as either TRUE or FALSE.

 

Following table summarizes the comparison operators.

 

Operator

Name

Example

Description

==

Equal

$a == $b

Return true if $a is equal to $b after type juggling.

===

Identical

$a === $b

Return true if $a is equal to $b, and they are of the same type.

!=

Not equal

$a != $b

Return true if $a is not equal to $b after type juggling.

<> 

Not equal

$a <> $b

Return true if $a is not equal to $b after type juggling.

!==

Not identical

$a !== $b

Return true if $a is not equal to $b, or they are not of the same type.

Less than

$a < $b

Return true if $a is strictly less than $b.

<=

Less than or equal to

$a <= $b

Return true if $a is less than or equal to $b.

Greater than

$a > $b

Return true if $a is strictly greater than $b.

>=

Greater than or equal to

$a >= $b

Return true if $a is greater than or equal to $b.

 

comparison_operators_demo.php

#!/usr/bin/php

<?php
$a = 10;
$b = 11;
$c = '10';

echo "a : $a\n";
echo "b : $b\n";
echo "c : '$c'\n";

echo "\n" . '$a == $b : ';
var_dump($a == $b);

echo '$a == $c : ';
var_dump($a == $c);

echo '$a != $b : ';
var_dump($a != $b);

echo '$a != $c : ';
var_dump($a != $c);

echo '$a === $b : ';
var_dump($a === $b);

echo '$a === $c : ';
var_dump($a === $c);

echo '$a !== $b : ';
var_dump($a !== $b);

echo '$a !== $c : ';
var_dump($a !== $c);

echo '$a < $b : ';
var_dump($a < $b);

echo '$a > $b : ';
var_dump($a > $b);

echo '$a <= $b : ';
var_dump($a <= $b);

echo '$a >= $b : ';
var_dump($a >= $b);

echo '$a < $c : ';
var_dump($a < $c);

echo '$a > $c : ';
var_dump($a > $c);

echo '$a <= $c : ';
var_dump($a <= $c);

echo '$a >= $c : ';
var_dump($a >= $c);

?>

Output

#!/usr/bin/php

<?php
$a = 10;
$b = 11;
$c = '10';

echo "a : $a\n";
echo "b : $b\n";
echo "c : '$c'\n";

echo "\n" . '$a == $b : ';
var_dump($a == $b);

echo '$a == $c : ';
var_dump($a == $c);

echo '$a != $b : ';
var_dump($a != $b);

echo '$a != $c : ';
var_dump($a != $c);

echo '$a === $b : ';
var_dump($a === $b);

echo '$a === $c : ';
var_dump($a === $c);

echo '$a !== $b : ';
var_dump($a !== $b);

echo '$a !== $c : ';
var_dump($a !== $c);

echo '$a < $b : ';
var_dump($a < $b);

echo '$a > $b : ';
var_dump($a > $b);

echo '$a <= $b : ';
var_dump($a <= $b);

echo '$a >= $b : ';
var_dump($a >= $b);

echo '$a < $c : ';
var_dump($a < $c);

echo '$a > $c : ';
var_dump($a > $c);

echo '$a <= $c : ';
var_dump($a <= $c);

echo '$a >= $c : ';
var_dump($a >= $c);

?>


Note

If one operand is a number and the other one is a numeric string, then the comparison is done numerically.



 

 

 

Previous                                                    Next                                                    Home