Skip to main content

Posts

Showing posts from December, 2018

php logic one

Querstion :- find login to print 1.input => ab output => a, ab, b 2. bana output => b, ba, ban, bana, a, an, ana, n,na, a Ans :- $str = "12345"; $ar = []; for($ui=0; $ui < strlen($str); $ui++) {   $newstr = ($ui != 0)?substr($str, $ui):$str;    for($i=1; $i <= strlen($newstr); $i++) {     $ar[] = substr($newstr, 0, $i);   } } echo "<pre>"; print_r($ar); Output :- Array ( [0] => 1 [1] => 12 [2] => 123 [3] => 1234 [4] => 12345 [5] => 2 [6] => 23 [7] => 234 [8] => 2345 [9] => 3 [10] => 34 [11] => 345 [12] => 4 [13] => 45 [14] => 5 )