Johnny Prescott
Johnny Prescott

Reputation: 271

How to echo a specific data from an array in php?

I want to take a specific from an array I have created.

Here's the code:

        try
    {
    // Conecting to MySQL
    $bdd = new PDO('mysql:host=localhost;dbname=horse', 'root', '');
    }
    catch(Exception $e)
    {
    // ERROR MESSAGE
    die('Erreur : '.$e->getMessage());
    }

    // Fetching the data from the table
    $reponse = $bdd->query('SELECT * FROM videos');

    $vidarray = array();

    while ($donnees = $reponse->fetch())
    {
    $videolink = $donnees['link'];

    $vidarray = array($videolink);

    print_r($vidarray);
    }
    echo $vidarray[1]);

    $reponse->closeCursor(); // Closing the request

I want to echo one of these specific data like this

echo $array[1];

I want this to output "WubVcOaW-qs" with this.

I am relativly new to php and I am sure this is pretty basic but can't find it anywhere.

Thanks,

Upvotes: 0

Views: 117

Answers (1)

raidenace
raidenace

Reputation: 12836

$array = array(
'S01tE08GSNg',
'WubVcOaW-qs',
'2n0ag4qmG5g',
'ni1UR-lXiZo',
'ynvz8P_aFwk'
);

echo $array[1];

Upvotes: 2

Related Questions