Example #1
0
<?php

function draw_stars($array)
{
    foreach ($array as $value) {
        if (is_numeric($value)) {
            for ($i = 0; $i < $value; $i++) {
                echo "*";
            }
        } else {
            for ($j = 0; $j < strlen($value); $j++) {
                $first_letter = substr($value, 0, 1);
                $first_letter = strtolower($first_letter);
                echo $first_letter;
            }
        }
        echo "<br>";
    }
}
$x = array(4, 6, 1, 3, 5, 7, 25);
$y = array(4, "Tom", 1, "Michael", 5, 7, "Jimmy Smith");
draw_stars($x);
draw_stars($y);
<?php

function draw_stars($array)
{
    for ($i = 0; $i < count($array); $i++) {
        if (!is_numeric($array[$i])) {
            for ($k = 0; $k < strlen($array[$i]); $k++) {
                echo strtolower(substr($array[$i], 0, 1));
            }
            echo '<br>';
        } else {
            for ($j = 0; $j < $array[$i]; $j++) {
                echo "*";
            }
            echo "<br>";
        }
    }
}
$x = array(4, "Tom", 1, "Michael", 5, 7, "Jimmy Smith");
draw_stars($x);
Example #3
0
                $star[] = '*';
            }
            $stars[$int] = implode($star);
        } else {
            for ($str = 0; $str < strlen($stars[$int]); $str++) {
                $star[] = strtolower($stars[$int][0]);
            }
            $stars[$int] = implode($star);
        }
    }
    foreach ($stars as $star) {
        echo $star . '<br>';
    }
}
/*
	$array = array(4, 6, 1, 3, 5, 7, 25);
	function draw_stars($stars) {
		for($int = 0; $int < count($stars); $int++) {
			$star = array();
			for($j = 0; $j < $stars[$int]; $j++) {
				$star[] = '*';
			}
			$stars[$int] = implode($star);
		}
		foreach($stars as $star) {
			echo $star . '<br>';
		}
	}
*/
draw_stars($array);
Example #4
0
<?php 
function draw_stars($array)
{
    for ($i = 0; $i < count($array); $i++) {
        if (is_string($array[$i])) {
            for ($j = 0; $j < strlen($array[$i]); $j++) {
                echo $array[$i][0];
            }
            echo "<br />";
        } else {
            for ($j = 0; $j < $array[$i]; $j++) {
                echo "*";
            }
            echo "<br />";
        }
    }
}
$A = array(1, 5, 7, 25, "yo", "howdy");
draw_stars($A);
Example #5
0
<?php

function draw_stars()
{
    $x = array(4, 'Tom', 1, 'Michael', 5, 7, 'Jimmy Smith');
    foreach ($x as $stars) {
        if (is_int($stars) == true) {
            for ($i = 1; $i <= $stars; $i++) {
                echo "*";
            }
        } else {
            for ($i = 1; $i <= strlen($stars); $i++) {
                echo str_repeat($stars[0], $i);
            }
        }
        echo "<br>";
    }
}
draw_stars();