PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
PHP allows the use of array syntax to reference characters in a string. If $out[2] holds the string 'ABCDE', $out[2][3] will reference the character at offset 3, which is 'D'. Characters do not have offsets, so $out[2][3][1] (offset 1 of 'D') does not make sense.
I understood the problem. Isn't there any other solution to this problem. as I am getting this '$abc' array dynamically. so enforce it to have uniform depth is a bit more complex.
"Garbage in, garbage out." You can (1) reject user input that does not conform, (2) attempt to make it conform and risk having the application do something that the user does not expect, or (3) blindly process any input and hope nothing breaks. In some situations, the second option makes sense, but I hope you would usually choose the first. You may agree that the first option is a smaller burden than the second and certainly less risky than the third.
Computers don't like ambiguity. If you don't enforce uniform depth, what does the input mean?
Testing for uniformity is actually not too difficult. Loop though the input array and make sure the number of colons in each key is consistent. At the same time, you should probably test that the characters between the colons are safe to run though eval() (to prevent eval() injection). Perhaps limit them to digits of a reasonable length. Definitely reject square brackets and semicolons. Functions like preg_match() can be helpful.
Hey thanks a lot. I will go for uniformity. This approach sounds good.
Actually I am a newbie to php . I am unable to understand "Garbage in, garbage out.". If you have time could you tell me in brief what does this actually mean.
Wikipedia wrote:Garbage In, Garbage Out is a phrase in the field of computer science or information and communication technology. It is used primarily to call attention to the fact that computers will unquestioningly process the most nonsensical of input data (garbage in) and produce nonsensical output (garbage out).