Вы можете присоединить событие к элементу при динамическом создании с помощью jQuery(html, attributes)
.
Начиная с jQuery 1.8, любой метод экземпляра jQuery (метод
jQuery.fn
) можно использовать как свойство объекта, переданного второму параметру:
function handleDynamicElementEvent(event) { console.log(event.type, this.value) } // create and attach event to dynamic element jQuery("
Я считаю, что это то, что вы ищете:
class Maker
{
private $arrayContainer = []; // Make public if you want to access it `$maker->arrayContainer`
function set(string $key, $value = [])
{
$this->arrayContainer[$key] = $value;
}
function get(string $key,$default=null){
return isset($this->arrayContainer[$key])?$this->arrayContainer[$key]:$default;
}
function all(){
return $this->arrayContainer;
}
}
$maker = new Maker();
$maker->set('a');
$maker->set('b', [1,2,3,4,5]);
$maker->set('c', ['a'=>1,'b'=>2,'c'=>3]);
//Get a specific index from the Maker class
print_r($maker->get('b'));
//Get the arrayContainer from the Maker Class
print_r($maker->all());
Надеюсь, это поможет,
Я бы пошел с рекурсией
class Maker
{
public $array = [];
function set($key, $value = []) {
$this->_set($this->array, $key, $value);
}
private function _set(&$array, $key, $value) {
if (is_array($array)) {
if (empty($array))
$array[$key] = $value;
else {
foreach ($array as $k => $v) {
$this->_set($array[$k], $key, $value);
break;
}
}
}
}
}
Вывод:
Array
(
[a] => Array
(
[b] => Array
(
[c] => 100
)
)
)
Я думаю, что это более подходит
class Maker
{
public $array = [];
function set($key, $value = [])
{
$this->array[$key] = $value;
}
}
$maker = new Maker();
$maker->set('a', array( 'VAL1', 1 ));
$maker->set('b', array( 'VAL1', array ( 'VAL2', 2 ) ));
$maker->set('c' , array( 'VAL1', array ( 'VAL2', array ( 'VAL3', 3 ) ) ));
var_dump($maker->array);