PHP code example of coco-project / magic-access
1. Go to this page and download the library: Download coco-project/magic-access library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
coco-project / magic-access example snippets
new \Coco\magicAccess\MagicArray();
$m[] = 'array';
$m[][] = 'array222';
var_export($m->getData());
/*
[
0 => 'array',
1 => [
0 => 'array222',
],
]
*
*/
= new \Coco\magicAccess\MagicArray();
$m[100] = 111;
$m['a'] = 'aaa';
$m['b'] = [];
$m['b'][] = 'aaa111';
$m['b'][][] = 'aaa111222';
var_export($m->getData());
/*
[
100 => 111,
'a' => 'aaa',
'b' => [
0 => 'aaa111',
1 => [
0 => 'aaa111222',
],
],
]
*/
A
{
use \Coco\magicAccess\MagicMethod;
}
$a = new A();
$a->b = [];
$a->b[] = 'a';
$a->b[][] = 'b';
$a->b[][]['h'] = 'c';
//b
echo $a->b[1]['0'];
//c
echo $a->b[2][0]['h'];
A
{
use \Coco\magicAccess\MagicMethod;
}
$a = new A();
$a->b = [];
$a->c = 123456;
$bb = &$a->c;
$bb = 888888;
//888888
echo $a->c;
unset($a->c);
array_push($a->b, 1);
array_push($a->b, 2);
print_r($a);
/*
Object
(
[b] => Array
(
[0] => 1
[1] => 2
)
)
*/
new \Coco\magicAccess\MagicArray();
array_push($m[], 212);
array_push($m[1], 22);
//212
print_r($m[0][0]);