I have a variable name $accountNumber
which holds a 9 digit number. When a user types it in and when it is displayed, it is cut up in 9 separate box's.
Like so:
When getting the account number I do something like this:
//$data['acountNumber'] = 453554334;
$accountNumber = (string)$data['accountNumber'];
$accountNumber_0 = $accountNumber[0];
$accountNumber_1 = $accountNumber[1];
$accountNumber_2 = $accountNumber[2];
$accountNumber_3 = $accountNumber[3];
$accountNumber_4 = $accountNumber[4];
$accountNumber_5 = $accountNumber[5];
$accountNumber_6 = $accountNumber[6];
$accountNumber_7 = $accountNumber[7];
$accountNumber_8 = $accountNumber[8];
However, if I don't have an account number listed, I get an Uninitialized string offset error. I can make this "go away" if I add an @
in font of each $accountNumber[#]
but I thought I would ask you guys if there is a better way at handling this.
What do you think?
EDIT - After accepted answer
The below answers work great. But since I needed to have my array be size 9 no matter what, I found that this works best.
$accountNumber = array_pad(str_split($data['accountNumber']), 9, '');