<?php $list = ['a', 'b', 'c']; $count = [1, 3, 5]; function stringFormatter($c, $i) { return "Char is $c & Int is $i"; } for ($i = 0; i < $list; $i++) { for ($j = 0; $j < $count; $j++) { $string = stringFormatter($list[$i], $count[$j]); print $string; } } ?>
This is a sample code I rewrote to demonstrate a problem I'm having in a program where I want to allocate a formatted string using the correct combination of char and int to be able to execute a SQL statement , using say string. The ideal situation is to get a string that has a combination of both char and int at that position in their respective lists. For example. "Char is a and Int is 1". It currently doesn't compile and when I plug it into the "Online PHP Sandbox" I get the error: "Internal Server Error [500]". Any suggestions on how to make it work or even other suggestions are welcome! Thanks in advance!
Hope it helps you
for ($i = 0; i
There are some syntax errors here - note the missing $ (look at the i inside the outer loop). You're probably referring to $i using the built-in counting function
More generally, there is a set of functions built into php that handle passing values into mysql (etc.) better - you should probably consider using these - search for "clean" using php and mysqli. p>