lorenzo314737 Posted November 4, 2021 Share Posted November 4, 2021 <> So ive found this code on the internet, but i dont understand the code. Can someone please help me? <?php $numbers= "2323"; $position = "RLRR"; $x = 1; if (isset( $_GET['position'])){ $position = $_GET['position']; } for ($y =0; $y < strlen ($position); $y++) { $href = $position; $check = $position; $color = "red"; if ( $href [$y] === 'L' ) { $href [$y] = 'R'; } else { $href [$y] = 'L'; } $right = substr ($check, 0, $y); $right = str_replace ("L", "", $right); $right = strlen ($right); $left = substr ($check, $y); $left = str_replace ("R", "", $left); $left = strlen ($left); if ( intval ($numbers [$y]) === $right+$left) { $color= "green"; } if (($color ) === "green") { $x ++; } ?> <td class=<?php echo $color; ?> ><?php echo $numbers[$y];?></td> <td> <a href="?position=<?php echo $href;?>"> <img class="<?php echo $position [$y];?>" src="Pijllinks.jpg"></a> </td> <?php } if (intval ($x) === 6) { $b="green"; } else return ?> Quote Link to comment https://forums.phpfreaks.com/topic/314164-i-need-help-with-a-php-code/ Share on other sites More sharing options...
gw1500se Posted November 4, 2021 Share Posted November 4, 2021 First please use the code icon (<>) at the top of the menu for your code and specify PHP. Second, your question is too broad. What specifically don't you understand? Quote Link to comment https://forums.phpfreaks.com/topic/314164-i-need-help-with-a-php-code/#findComment-1591751 Share on other sites More sharing options...
lorenzo314737 Posted November 4, 2021 Author Share Posted November 4, 2021 Im new to php and want to know what the code means... Quote Link to comment https://forums.phpfreaks.com/topic/314164-i-need-help-with-a-php-code/#findComment-1591752 Share on other sites More sharing options...
gw1500se Posted November 4, 2021 Share Posted November 4, 2021 (edited) Rather then starting with a chunk of code from the internet which may or may not even work, I suggest you start with the PHP manual tutorial. Edited November 4, 2021 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/314164-i-need-help-with-a-php-code/#findComment-1591753 Share on other sites More sharing options...
Barand Posted November 4, 2021 Share Posted November 4, 2021 You want us to help you to pass off a piece of code that you found as your work so you can submit it as your homework assignment? Quote Link to comment https://forums.phpfreaks.com/topic/314164-i-need-help-with-a-php-code/#findComment-1591754 Share on other sites More sharing options...
lorenzo314737 Posted November 4, 2021 Author Share Posted November 4, 2021 No. I am really bad at coding. My teacher didnt give us information. We have to figure it out ourslves. I only know the basics of php and thats NOT enough for this puzzle game. I told my teacher i dont understand several times. He gave me this code of another student, so i could learn how to code it, but i dont understand and he doesnt explain it to me. So thats why i asked for help. Quote Link to comment https://forums.phpfreaks.com/topic/314164-i-need-help-with-a-php-code/#findComment-1591755 Share on other sites More sharing options...
Barand Posted November 4, 2021 Share Posted November 4, 2021 Try these links https://www.php.net/substrhttps://www.php.net/strlenhttps://www.php.net/str_replacehttps://www.php.net/issethttps://www.php.net/intval Quote Link to comment https://forums.phpfreaks.com/topic/314164-i-need-help-with-a-php-code/#findComment-1591757 Share on other sites More sharing options...
gizmola Posted November 4, 2021 Share Posted November 4, 2021 First thing is that the code you pasted was syntactically incorrect. I fixed it and put your post into code tags, as well as indenting it correctly for the blocks. To be able to read and understand code, it needs to be indented properly. Concept: A php file can have both html and php blocks. A php block must start with <?php and end with ?>. If you put html markup in a php file, it will be seen as html markup, unless it is inside a php block. Do you understand how that is used in the file you presented? Are there any html blocks? Does the script drop in and out of php? Is there html intermixed with php? Do you understand what a function is/does? Barand helpfully posted links to some key php functions and language constructs used in this code. Did you review those? If you have done that, then if you can narrow down the code into specific sections of code you don't understand, people will be happy to help you with those. The journey of a thousand miles begins with a single step. Be curious and read and study the material we provided. Curiosity and focus are the keys to learning anything new, not just programming languages. Do you have a php environment setup where you can test the code? Being able to put in echo and print_r or var_dump statements are very helpful when studying code you don't understand fully. 1 Quote Link to comment https://forums.phpfreaks.com/topic/314164-i-need-help-with-a-php-code/#findComment-1591761 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.