3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $value1 = $value2 = 0; $searches = array( "Bredd:", "bredd:", "Bredd=", "bredd=", "Bredd ", "bredd ", "Höjd:", "höjd:", "Höjd=", "höjd=", "Höjd ", "höjd ", ); $tests = array( "Höjd=25,bredd=35", "Höjd=100,bredd=81", "Höjd = 25,bredd = 35", "Höjd:25,bredd:35", "Höjd: 25,bredd: 35", "Höjd : 25,bredd : 35" ); foreach( $tests as $test) { $mSpecParts = explode( ',', $test ); foreach( $mSpecParts as $i => $part ) { $str = ""; foreach( $searches as $search ) { if( strpos( $part, $search) !== false ) { $str = explode( $search, $part ); $str = $str[count($str)-1]; } } if( strlen( $str ) ) { if( $value1 ) { echo " Setting value2 to " . trim( $str ) . "\n"; $value2 = trim( $str ); }else{ echo " Setting value1 to " . trim( $str ) . "\n"; $value1 = trim( $str ); } } } if( $value2 > $value1 ) { $tmp = $value2; $value2 = $value1; $value1 = $tmp; } echo "\n value1 = $value1 & value2 = $value2"; }
based on EhAif
Output for 5.6.38 - 7.3.0rc3
Setting value1 to 25 Setting value2 to 35 value1 = 35 & value2 = 25 Setting value2 to 100 Setting value2 to 81 value1 = 81 & value2 = 35 Setting value2 to = 25 Setting value2 to = 35 value1 = = 35 & value2 = 81 Setting value2 to 25 Setting value2 to 35 value1 = = 35 & value2 = 35 Setting value2 to 25 Setting value2 to 35 value1 = = 35 & value2 = 35 Setting value2 to : 25 Setting value2 to : 35 value1 = = 35 & value2 = : 35