0
$arr = array(1 => "rambow", 2 => "rambow", 3 => "popcorn", 4 => "rambow");

how do i make it in simpler format so i dont have to keep typing "rambow" for every number that => "rambow"

? cause theres a lot of "rambow" for a whole bunch of numbers. isnt there any easier way to do this?

Edited by SKANK!!!!!: n/a

5
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by OS_dev
2
$arr = array_fill_keys(range(1,4), "rambow");
$arr[3] = "popcorn";

Edited by Simon Tite: n/a

0
$arr = array(1 => "rambow", 2 => "rambow", 3 => "popcorn", 4 => "rambow");

how do i make it in simpler format so i dont have to keep typing "rambow" for every number that => "rambow"

? cause theres a lot of "rambow" for a whole bunch of numbers. isnt there any easier way to do this?

How many "rambow" do you want to add on your array? Is it (rambow) inserted on any value on the array? Is "rambow" in the array inserted randomly?

0
<?php
$arrayFill = array();
$arrayFill["rambow"] = ":0:1:3:5:6:7:8:9:11:12:13:15:16:18:21:22:";
$arrayFill["popcorn"] = ":2:4:10:14:17:19:20:";
$default = "default";

$arr = array();
$totalLen = 22;
for($i = 0; $i < $totalLen; $i++)
{
    $fillvalue = "";
    foreach($arrayFill as $key=>$value)
    {
        if(strpos($value, ":" . $i . ":") === false) continue;

        $fillvalue = $key;
    }

    $arr[$i] = trim($fillvalue) == ""?$default:$fillvalue;
}
?>

Edited by OS_dev: n/a

0

or better yet

<?php
$arrayFill = array();
$arrayFill["popcorn"] = ":2:4:10:14:17:19:20:";
$default = "rambow";

$arr = array();
$totalLen = 22;
for($i = 0; $i < $totalLen; $i++)
{
    $fillvalue = "";
    foreach($arrayFill as $key=>$value)
    {
        if(strpos($value, ":" . $i . ":") === false) continue;

        $fillvalue = $key;
    }

    $arr[$i] = trim($fillvalue) == ""?$default:$fillvalue;
}
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.