-4

I can’t see the problem here. I have an array, and I would like to take out the information I need, by using this code, but I doesn’t seems to be working, and I don’t know why:

$member = array_slice($members, 0, 1); 
print_r($member);

$event=($member["title"]);
$content=($member["content"]);      
$day=($member["day"]);
$month=($member["month"]);
$year=($member["year"]); 
Array ( 
    [0] => Array ( 
        [title] => Daniel Ryan 
        [content] => Daniel-Ryan Spaulding is an Internationally-Touring Canadian Stand-Up Comedian, who has performed extensively in 35 countries worldwide. His comedy delves into traveling, international politics & gay rights. His intelligent cultural and social observations, high-energy, and brutal-but-polite sense of humor has won him fans across Europe. He appears regularly at the biggest comedy clubs & festivals in Scandinavia, had his hour-long comedy special air on TV2 Zulu, and was the first openly gay comedian to perform throughout Eastern Europe & China ! Get tickets in the door. 100kr 
        [imagename] => aarhuspride.jpg 
        [slug] => 20140517 
        [day] => 17 
        [month] => 05 
        [year] => 2014 
        [id] => 20140517.json 
    ) 
) 

Notice: Undefined index: title in C:\xampp\htdocs\kode\projekter\eksamen_tore\gemdata.php on line 44

Notice: Undefined index: content in C:\xampp\htdocs\kode\projekter\eksamen_tore\gemdata.php on line 45

Notice: Undefined index: day in C:\xampp\htdocs\kode\projekter\eksamen_tore\gemdata.php on line 46

Notice: Undefined index: month in C:\xampp\htdocs\kode\projekter\eksamen_tore\gemdata.php on line 47

Notice: Undefined index: year in C:\xampp\htdocs\kode\projekter\eksamen_tore\gemdata.php on line 48
JJJ
  • 32,902
  • 20
  • 89
  • 102

3 Answers3

1

Array ( [0] => Array ( is the part you're missing. You basically have

array(
    array(
        'title' => 'Dan Ryan',
    )
)

As a suggestion, don't use array_slice to extract a single-element subarray but simply use $members[$i] to extract a single element.

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
1

This may help you

$event=($member[0]["title"]);
$content=($member[0]["content"]);      
$day=($member[0]["day"]);
$month=($member[0]["month"]);
$year=($member[0]["year"]); 

your array is two dimensional your data title,content etc is contains inside Array $member[0] that is the reason it gives you error of undefined index

AmanS
  • 1,490
  • 2
  • 13
  • 22
0

You're starting with an array of arrays. array_slice() returns an array, albeit in this case of just one element, which is itself an array.

Either change the first line to

$member = $members[0];    // Get the first element of $members

or change the indexes to

$event=($member[0]["title"]);
$content=($member[0]["content"]);      
$day=($member[0]["day"]);
$month=($member[0]["month"]);
$year=($member[0]["year"]);