Jump to content

<> I need help with a PHP code


lorenzo314737

Recommended Posts

<>

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 
?>


 

 

Link to comment
Share on other sites

  • lorenzo314737 changed the title to <> I need help with a PHP code

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. 

 

Link to comment
Share on other sites

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.

 

  • Great Answer 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.