Bifalgorithm post · Computer science one · Basics

How are PHP strings copied and modified by character?

How are PHP strings copied and modified by character? (Computer science one · Basics) — "The assignment operator can also be used to make copies of strings.\n\…

Ideas in this flowchart

  • String copying and character modification with the assignment operator
  • The assignment operator can copy a string.
  • The copy is deep, so changes to the first string do not affect the second.
  • $firstName = "Thomas";\n$alias = $firstName;
  • Individual characters can be changed by treating a string like an array.
  • String positions use zero-based indexing.
  • $a = "hello";
  • $a[0] = "H";\n$a[5] = "!";
  • The string becomes "Hello!".
Feed/

How are PHP strings copied and modified by character?

No cover

Channel

Computer science one

1 page

"The assignment operator can also be used to make copies of strings.\n\n1 $firstName = \"Thomas\";\n\n2 $alias = $firstName;\n\nIt is important to understand that this assignment makes a deep copy of the string. Changes to the first do not affect the second one. You can make changes to individual characters in a string by treating it like a zero-indexed array.\n\n1 $a = \"hello\";\n\n2 $a[0] = \"H\";\n\n3 $a[5] = \"!\";\n\n4 //a is now \"Hello!\""

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.