Ahsan Ahsan -3 years ago 123
PHP Question

Country Name Pattern

I am Confused how to make a country name pattern like star pattern in php

For Example I want to make A pattern Like This in php Using Arrays And For Loops Can any one help me I didn't find on Internet.

P

PA

PAK

PAKI

PAKIS

PAKIST

PAKISTA

PAKISTAN

Answer Source
<?php
$country="AUSTRALIA";
$len=strlen($country);
for($i=1;$i<=$len;$i++)
{
  echo substr($country,0,$i),"\n";
}
?>

Output

A
AU
AUS
AUST
AUSTR
AUSTRA
AUSTRAL
AUSTRALI
AUSTRALIA

Fiddle

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download