만약 내가 미리 어레이에서는 같은 정의 (I don& 정의하십시오, t # 39 는 크기):
$cart = array();
추가 요소를 통해 이 같은 앨리어스가 합니까?
$cart[] = 13;
$cart[] = "foo";
$cart[] = obj;
'Array_push' 과 방법을 모두 설명됨 작동합니다.
$cart = array();
$cart[] = 13;
$cart[] = 14;
// etc
//Above is correct. but below one is for further understanding
$cart = array();
for($i=0;$i<=5;$i++){
$cart[] = $i;
}
echo "<pre>";
print_r($cart);
echo "</pre>";
동일합니다.
<?php
$cart = array();
array_push($cart, 13);
array_push($cart, 14);
// Or
$cart = array();
array_push($cart, 13, 14);
?>
//We don't need to define the array, but in many cases it's the best solution.
$cart = array();
//Automatic new integer key higher than the highest
//existing integer key in the array, starts at 0.
$cart[] = 13;
$cart[] = 'text';
//Numeric key
$cart[4] = $object;
//Text key (assoc)
$cart['key'] = 'test';
Array_push 사용할 수 있습니다. 이 같은 요소를 추가하므로 끝까지 어레이이며 스택에서.
또한 외상때문에 done it 다음과 같습니다.
$cart = array(13, "foo", $obj);
이 방법을 사용하여 먼저 너희에게베풀어진 덮어씁니다 배열에서 경우에만 복제본인지 확실하지!
$arr1 = $arr1 + $arr2;
([지켜보리니 소스] (https://stackoverflow.com/a/2140094/2165415))
$products_arr["passenger_details"]=array();
array_push($products_arr["passenger_details"],array("Name"=>"Isuru Eshan","E-Mail"=>"[email protected]"));
echo "<pre>";
echo json_encode($products_arr,JSON_PRETTY_PRINT);
echo "</pre>";
//OR
$countries = array();
$countries["DK"] = array("code"=>"DK","name"=>"Denmark","d_code"=>"+45");
$countries["DJ"] = array("code"=>"DJ","name"=>"Djibouti","d_code"=>"+253");
$countries["DM"] = array("code"=>"DM","name"=>"Dominica","d_code"=>"+1");
foreach ($countries as $country){
echo "<pre>";
echo print_r($country);
echo "</pre>";
}
$cart = array();
$cart[] = 11;
$cart[] = 15;
// etc
//Above is correct. but below one is for further understanding
$cart = array();
for($i = 0; $i <= 5; $i++){
$cart[] = $i;
//if you write $cart = [$i]; you will only take last $i value as first element in array.
}
echo "<pre>";
print_r($cart);
echo "</pre>";
한 때 부터 시작하는 게 아니라 이 사용할 수 있는 요소를 추가되도록 요소점 인덱스화를, 그런 것 같아요.
// adding elements to an array with zero-based index
$matrix= array();
$matrix[count($matrix)]= 'element 1';
$matrix[count($matrix)]= 'element 2';
...
$matrix[count($matrix)]= 'element N';