0

I want to make an array like the one below:

$database = array(
    array(
        "key" => "Key1",
        "hwid" => "Hwid1"
    ),
    array(
        "key" => "Key2",
        "hwid" => "Hwid2"
    ),
);

How would I go about making this by inserting values. Here is what I have tried:

$array = array();
$array[array()["key"]] = "Key1";
$array[array()["hwid"]] = "HWID1";

Sadly the above code does not make the structure of the array that I wanted. How would I achieve this?

3 Answers 3

1
$array = [];
$array[] = ["key" => "Key1","hwid" => "Hwid1"];
$array[] = ["key" => "Key2","hwid" => "Hwid2"];

or

$array = [
    ["key" => "Key1","hwid" => "Hwid1"],
    ["key" => "Key2","hwid" => "Hwid2"]
];
Sign up to request clarification or add additional context in comments.

Comments

1
$array = array();
$arr1 = ["id" => "id1", "hwid" => "hwid1"];
$arr2 = ["id" => "id2", "hwid" => "hwid2"];
array_push($array, $arr1, $arr2);
var_dump($array);

You don't need array index to be an array

Comments

0

Your parent array is not associative, the only way you can access to it is by int index which starts with 0:

try this:

$array = array();
$array[0]["key"] = "Key1";
$array[0]["hwid"] = "HWID1";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.