Answers for "get object keys and entries in php"

PHP
1

php get object keys

<?php

class foo {
    private $a;
    public $b = 1;
    public $c;
    private $d;
    static $e;
   
    public function test() {
        var_dump(get_object_vars($this));
    }
}

$test = new foo;
var_dump(get_object_vars($test));

$test->test();

?>
Posted by: Guest on June-08-2021
3

php get keys and values from array

foreach($yourArray as $key => $value) {
    echo '<a href="' . $value . '">' . $key . '</a>';
}

// OR

//Use functions
key($array);     //Returns current key
reset($array);   //Moves array pointer to first record
current($array); //Returns current value
next($array);    //Moves array pointer to next record and returns its value
prev($array);    //Moves array pointer to previous record and returns its value
end($array);     //Moves array pointer to last record and returns its value
Posted by: Guest on October-07-2021

Browse Popular Code Answers by Language