r/PHPhelp • • Mar 16 '26
Game Dev Learning PHP, Looking For Info About What A Couple Things Do/Mean
I'm learning PHP/SQL, and so far, I don't think i'm doing too bad! But I hit a point where I have to ask what a couple functions/whatever do/mean/are for. For context, what I'm doing is pulling from the database tables, I got to "WHERE created_date =" which is the column I made, but my base/engine is using variable $product_id, which = isset($_GET['product'] ? (int)$_GET['product'] : null;
Now, I understand isset, but I can't find the defining of $_GET to know what it does, and I don't understand what ['product'] is, I don't see it defined, can someone please explain what something in the [''] means/does and why/what for? That way I understand.
Also, if someone can tell me a way I can write a new var, that'll pull the data from that table column, instead of deciphering this, cloning it, and basically doing that anyways, it would be a HUGE help. But because I wanna learn, I would like to know what these syntaxes mean/do so I better understand the program.
I also have several variables that are like $comments[4], in my video game programming, "Name[Index of 0-infinity] is an array. Is this also an array in PHP? If so, I already kind of understand. But I wanna be sure.
I think that's all I need to know for now! I'm not looking for someone to write my code for me, just help me understand it better so I can do for myself! I tried to explain what I understand to show my competency to prove that, so any of you masters that are willing to help explain, I would very much appreciate it! I've learned a LOT in the last 48 hours just by asking questions like this and a few YouTube videos! Please help me keep it up!!
4
u/martinbean Mar 16 '26
Hey! I’m in the complete opposite boat! Longtime PHP developer (15+ years) currently learning game development, and reverse-engineering PlayStation 1 games. So happy to help out.
12
u/indukts Mar 16 '26
$_GET - https://www.php.net/manual/en/reserved.variables.get.php
PHP assoc arrays - https://www.geeksforgeeks.org/php/associative-arrays-in-php/
These 2 links I believe will answer your questions. Good luck!
6
u/MateusAzevedo Mar 16 '26
It seems you're jumping ahead and skipping some basic syntax and concepts.
Maybe that's the issue, a least I don't think that's a good way to learn a new language. If you were following an actual course, they for sure would explain that arrays in PHP can work like a dictionary/hashmap (that's what
'product'is). Even if you just read the PHP manual, it explains what $_GET is.So my recommendation is to go with a course, that has a structured learning path, so you don't skip important bits. Current good courses: Program with Gio (Youtube) and Laracasts (Youtube/laracasts.com). If your prefer books, Jon Duckett has a good one.
1
u/xreddawgx Mar 17 '26 edited Mar 17 '26
Product is the ?product=<slug> in the url
$comments is an array. ALL arrays start at 0. So its referencing the 5th array index. 0,1,2,3,4 - 5 indices.
1
u/colshrapnel Mar 17 '26
Here you go: if the page address contains ?var=value[&var=value&...], PHP fills the $_GET array with elements where var becomes a key and value the corresponding value. So you can get value by writing $_GET['var'] in your code.
Note that arrays in PHP are two in one. It's ether an array AND a dictionary. $_GET usually a dictionary, with key-value. So yes, $comments is also an array which acts like a regular array with 0-started numeric indices. Note that since it's two in one, unsetting one element from array doesn't reindex it, so you will have a gap. But well, just keep it in mind, as it's hardly relevant for you for now.
Note that '' is not a part of the key, that's just a string delimiter. It's the way you are writing strings in PHP. like, if you want to have product inside of a variable, you have to write is as 'product'. While [] is just a syntax for arrays. if you want to get some value from an array, you have to write its key inside brackets: $_GET['product'] will get you a $_GET array value under the key product.
I am not sure what you mean, because up until now you were talking about arrays, not database. But since you want to learn, here is my concise introduction to mysqli. Still I am not sure if it could be useful as it implies that you already have some experience with databases. Either way, just ask if something is unclear
-1
u/hausenfefr Mar 17 '26
on this spot in 2026;
Reddit user Smooth_Prompt_2086 was able to query the community on the meaning of GET... because of GET.
It has now been 7 hours, and they have yet to receive a valid answer.