3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Finding Floats in an Array */ $arr = [ // Short String '123', // Long String '123 and another float at the end 123.23', // Mixed String '4.7 + 99 / 8...8 00.b', // Float 123.444, // Decimal 444, ]; $pattern = '%(\d+)?\.\d+%'; var_dump(preg_grep($pattern, $arr)); /* Find occurrences of either a space at the start of the string or a "ing" word */ $arr2 = [ "Examine she brother prudent add day ham.\n Far stairs now coming bed oppose hunted become his. You zealously departure had procuring suspicion. Books whose front would purse if be do\n decay. Quitting you way formerly disposed perceive ladyship are. Common turned boy direct and yet.", "Behind sooner dining so window excuse he summer. \n Breakfast met certainty and fulfilled propriety led. Waited get either are wooded little her. Contrasted unreserved as mr particular\n collecting it everything as indulgence. Seems ask meant merry could put. Age old begin had boy noisy table front whole given.", "Enjoying minutes related as at on on. Is dried as often me. Goodness as reserved raptures to mistaken steepest oh screened he. Gravity he mr sixteen esteems. Mile home its new way with high told said. Finished no horrible blessing landlord\n dwelling dissuade if. Rent fond am he in on read. Anxious cordial demands settled entered in do to colonel.", " <p>Remaining lively hardly needed at do by. Two you fat downs three.\n True mr gone most at. Dare as name just when with it body. Travelling inquietude she increasing off impossible the. Cottage be noisier looking to we promise on. Disposal to kindness appetite diverted learning of on raptures.<br> Betrayed any may returned now dashwood formerly. Balls way delay shy man views. No so instrument discretion unsatiable to in.</p>", ]; $pattern = '%^(\s+)|^(\w+)(ing)%'; var_dump(preg_grep($pattern, $arr2)); /* Invert results with Flag */ var_dump(preg_grep($pattern, $arr2, PREG_GREP_INVERT));
based on XLE6n
Output for 7.1.25 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.24, 7.4.0 - 7.4.12, 8.0.0
array(3) { [1]=> string(39) "123 and another float at the end 123.23" [2]=> string(21) "4.7 + 99 / 8...8 00.b" [3]=> float(123.444) } array(2) { [2]=> string(354) "Enjoying minutes related as at on on. Is dried as often me. Goodness as reserved raptures to mistaken steepest oh screened he. Gravity he mr sixteen esteems. Mile home its new way with high told said. Finished no horrible blessing landlord dwelling dissuade if. Rent fond am he in on read. Anxious cordial demands settled entered in do to colonel." [3]=> string(434) " <p>Remaining lively hardly needed at do by. Two you fat downs three. True mr gone most at. Dare as name just when with it body. Travelling inquietude she increasing off impossible the. Cottage be noisier looking to we promise on. Disposal to kindness appetite diverted learning of on raptures.<br> Betrayed any may returned now dashwood formerly. Balls way delay shy man views. No so instrument discretion unsatiable to in.</p>" } array(2) { [0]=> string(285) "Examine she brother prudent add day ham. Far stairs now coming bed oppose hunted become his. You zealously departure had procuring suspicion. Books whose front would purse if be do decay. Quitting you way formerly disposed perceive ladyship are. Common turned boy direct and yet." [1]=> string(322) "Behind sooner dining so window excuse he summer. Breakfast met certainty and fulfilled propriety led. Waited get either are wooded little her. Contrasted unreserved as mr particular collecting it everything as indulgence. Seems ask meant merry could put. Age old begin had boy noisy table front whole given." }