Tag Archives: modify

Modify existing values in a PHP array

This tutorial explains how to modify existing values in a PHP array. It’s pretty simple – all you need to do is refer to the array and its index and then change that index’s value with another value.

Watch the video below and then scroll down to see the sample code.

Sample PHP code:

  // create a simple array with 12 elements inside it
  $months = array("January","February","March","April","May","June","July","August","September","October","November","December");
  // change the value of the second element in the array
  $months[1] = "Feb";

  // return the value of the second element in the arrray
  echo $months[1];

Accessing other objects and modifying their components

This tutorial explains how you can write a script in C# that can access other objects and then modify their components. In this example, we will attach a script to the Main Camera and then use that script to access a Cube object and modify it’s position, rotation and scale.

Here is the sample code that is attached to the Main Camera and accessing the Cube object.

using UnityEngine;
using System.Collections;
public class moveOtherObject : MonoBehaviour {
 // this script accesses another object and modifies its components
 // it can be attached to any other object e.g script and is accessing a Cube
 // this is the other game object you want to access
 public GameObject target;
 // Use this for initialization
 void Start () {
 target = GameObject.Find ("Cube");
 // Update is called once per frame
 void Update () {
 target.transform.Translate (0f, 0f, 0.1f);
 target.transform.Rotate (0f, 0f, 1f);
 target.transform.localScale = new Vector3 (1.5f, 1.5f, 1.5f);

Operators in JavaScript

In this tutorial, you will learn how to use a range of operators in JavaScript to assign values, modify variables and make calculations.

If you have created your own variables and assigned them each a value (such as a string or integer), then you will already be familiar with the assignment operator which is a single = (equals sign).

Operators include:

Addition +
Division /
Multiplication *
Modulus %
Equals =

You can view the video below to see how to use these operators and scroll down to see the sample code.


The code below shows how you can use a range of operators when working variable assignments and calculations.

<!DOCTYPE html>
<html lang="en">
 <meta charset="utf-8"/>
 <title>JavaScript - Operators</title>
 <script type="text/javascript">
 var x = 5, y = 10; //variables can be initialised on one line, separated by commas
 var z = x + y; // this is how variables can be added
 z++ //this increases the z variable value by 1
 z-- //this decreases the z variable value by 1
 // operators include + (plus) - (minus) * (multiply) / (divide) and % (modulus) which returns the remainder from division
 x+=y; //this is an example of compound addition. It is the equivalent of x = x + y
 // variables can be added using the compound addition += , compound subtraction -= , compound multiplication *= or compound addition /=
 document.write(z); // now let's see what the z variable displays after these modifications.

Next tutorial: Strings