Search code examples
phparraysstringstack-overflow

converting array into string with overflow in php


I have simple code:

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('html_errors', false);
$test = array();
$test = 'demo';
$test['55test'] = 'yay';
var_dump($test);

returns

 string(56) "demo                                                   y"

I know this is not proper way to convert string to array, but it seems that I've missed PHP docs about this case. Can anyone enlighten me regarding this? Thanks

P.S. Tested in PHP 5.3.6-13


Solution

  • String access and modification by character

    Characters within strings may be accessed and modified by specifying the zero-based offset of the desired character after the string using square array brackets, as in $str[42]. Think of a string as an array of characters for this purpose. The functions substr() and substr_replace() can be used when you want to extract or replace more than 1 character.

    Check the string manual