bertrc why the function, function create_table() the variable is not $my_data.
I contract someone to do a job for me, and I send them some "stuff". I call it one thing, but they, with their specialist knowledge of whatever it is I'm contracting them for, might call it something else. Doesn't matter what it's called: it's still the same stuff.
What gets sent to a function is a value, not the variable that contains the value. (The technical name for that value is that it's the function's "argument".) The first thing the
create_table function does when you call it is set
$data to be
['First piece of data','Second piece of data','And the third']. (This is called "pass by value"; there are alternatives: such as "pass by reference" and the one you're thinking of which is called "pass by name". But PHP uses pass-by-value, which is probably the commonest, so that's what I'm talking about here.)
You could write the call as
create_table(['First piece of data','Second piece of data','And the third']);
And then what would you expect the parameter to be named then?
Or think about the case where you want to call the function more than once
How would that work if all three variables had to have the same name?
Or look at the manual, where you have, for example,
strpos($haystack, $needle). You aren't expected to call the variables you're passing to it "haystack" and "needle", you're expected to call them names that make sense in your program. The writers of
strpos don't know your program so they don't know what names you'd use, they used names that made sense inside
And here's a thing to think about: if you had to use the same variable both in the function and when you called it ("pass by name"), you wouldn't need to pass it in the first place: the function would already have the variable (this is basically how
GO SUB worked in old BASIC).
(And, just as an aside: why the incredibly ancient loop inside the function?
foreach has been a thing since PHP 3.)
(As a second aside: if you really want readers of your code to know what parameter you're passing a value to you can write
(And a third aside: PHP does provide a mechanism for pass-by-reference, and it's still occasionally used; that's when you put the
& next to the parameter when you define the function.)