Answer the question
In order to leave comments, you need to log in
An error in the code. Loser level?
I get this error:
Parse error: syntax error, unexpected T_DOUBLE_ARROW, expecting ']' in Z:\home\zion.ru\www\function\articles.php on line 4
Here is the line itself:
$art1 ["id"= >1, "title"=>"Title1", "date"=>"12-10-2015", "content"=>"Content1"];
What is the problem?
Answer the question
In order to leave comments, you need to log in
$art1 = ["id"=>1, "title"=>"Title1", "date"=>"12-10-2015", "content"=>"Content1"];
function articles_all() {
$art1 = ["id"=>1, "title"=>"Title1", "date"=>"12-10-2015", "content"=>"Content1"];
$art2 = ["id"=>2, "title"=>"Title2", "date"=>"13-10-2015", "content"=>"Content2"];
$arr[0] = $art1;
$arr[1] = $art2;
return $arr;
}
// PHP 5.4+
function articles_all() {
return [
['id' => 1, 'title' => 'Title1', 'date' => '12-10-2015', 'content' => 'Content1'],
['id' => 2, 'title' => 'Title2', 'date' => '13-10-2015', 'content' => 'Content2']
];
}
So arrays in php do not need to be initialized this way.
The square quotes [] refer to a specific array value.echo $art1["id"];
I put the = sign and still the error is on line 4.
<?php
function articles_all() {
$art1 = ["id"=>1, "title"=>"Title1", "date"=>"12-10-2015", "content"=>"Content1"];
$art2 = ["id"=>2, "title"=>"Title2", "date"=>"13-10-2015", "content"=>"Content2"];
$arr[0] = $art1;
$arr[1] = $art2;
return $arr;
}
function articles_get($id) {
return ["id"=>1, "title"=>"Это простой заголовок", "date"=>"12-10-2015", "content"=>"Здесь будет статья"];
}
function articles_new($title, $date, $content) {
//Создание статьи
}
function articles_edit($id, $title, $date, $content) {
//Редактирование статьи
}
function articles_delete($id) {
//Удаление статьи
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question