I am a new user to PHP from C++/Python/Java. In PHP, there is a built-in array type, how can I prove the array is the same array after I insert a new object into it or a copy of the old one? In C++/Python/Java, I can use the object address, id(), or hashcode to test if the object is same, how can I do the same test in PHP?
<?php
$a['0'] = "a";
$a['1'] = 'b'; //here, $a is a new copied one or just a reference to the old?
?>
OK, I update my question, actually, there is no specific problem. I just want to know if the array object remains same before and after insert new values. In Python, I could make a test like this:
a = [1]
print id(a)
a.append(2)
print id(a)
BTW, this is the id() function manual in Python.
id(...)
id(object) -> integer
Return the identity of an object. This is guaranteed to be unique among
simultaneously existing objects. (Hint: it's the object's memory address.)
Code updated:
# -*- coding: utf-8 -*-
a = [1, 2, 3]
b = [1, 2, 3]
print id(a)
print id(b) //the id(b) is not same as id(a), so a and b has same content, but they both own their own values in the memory
c = a // c is a reference to a
c.append(4)
print c
print a //after appending a new value(which means insert a new value to array), a has same value as c
so the problem is I can prove the memory layout by code in both C++/Python/Java, I want to make sure if I can do the same thing in PHP.