abrad1212 abrad1212 - 4 months ago 29
PHP Question

PHP How can I store variables in an array and call them

Ok so yesterday I was working on a PHP API all day (2:30PM - 3:30AM CT).
The user/client/front end of the API can submit a filename or link to the API so it can view it, edit it, or delete it.

But that's a problem because if the user can do that that means they could edit or delete the website with the client.

So I'm wondering can I store a bunch of variables that are equal to links, so when the client submits, the API will see if that link is unauthorized or authorized

Could you do it like this

<?php
$myArray = array( //Unauthorized Links
$link1 => "http://example.com" //First Link
);
?>


Then check the links using $myArray?

If you need the API code I'll provide it.

Answer

use this code and it will work for you

<?php
    $myArray = array(
        1 => 'http://example-1.com',
        2 => 'http://example-2.com',
        3 => 'http://example-3.com',
        4 => 'http://example-4.com'
    );

    foreach($myArray as $key => $value){
        echo 'link '.$key.' = '.$value.' <br>';
    }
?>
Comments