PHP Arrays

Hi, today will go through two ways to indexing an array:
The index can be assigned automatically (index always starts at 0), like this:

$coding = array("PHP", "HTML", "XML");


or the index can be assigned manually (remember index always starts at 0 even if you start with 1)

$coding[0] = "PHP";
$coding[1] = "HTML";
$coding [2] = "XML";


Here an example of how you can use it

<?php
$coding = array("PHP", "HTML", "XML");
echo "I want to create a webpage based on " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>

Powershell Array

Here we have some more examples of you can do with Array

# $sampleData is a multi-dimensional array
$sampleData = (,(3,4,12),(5,-5,-25))

$sampleData.GetType()
$sampleData
#$sampleData[0] #It will combine first half
#$sampleData[1] #It will combine secound half



$animals = "cat", "dog", "bat"

$animals.GetType()
$animals[0]
#[0] = cat 
#[1] = dog 
#[2] bat

#Very importend its always starts on 0!

#$animals += "bird" 
#Now there is value [4] instead of three

#You can do the last thing like this too
#$animals = $animals + "new animal"




#$animals[1] = "Leeloo" 
#Now will dog be replaced by Leeloo



#$animals -ne 'cat' 
#If you want to remove cat



#$animals[1..2] 
#Display all value between values



#$animals[-1] #Fetch last recorded value



#$animals -like '*a*' 
#Search for a value with a in i it



############### Create a table with diffrent values ############### 

$obj = New-Object PSObject -Property @{
Name = "John"
Age = 10
}



Powershell hash tables in array

Let start create hashtables in array

#Store more then one hashtables in array

$User = @{
Login="JeaPic"
DisplayName="Jean-Luc Picard"
givenName="Jean-Luc"
sn="Picard"
Description="Commanding Officer"
},
@{
Login="WilRik"
DisplayName="William T Riker"
givenName="William"
sn="Riker"
Description="First Officer"
},
@{
Login="GeoLaF"
DisplayName="Geordi La Forge"
givenName="Geordi"
sn="La Forge"
Description="Chief Engineer"
}

To get hold of the information

$user This will Print all the information
$user[0] If you wish to get hold of one part or element
$user[0].Description You will only get field Description
$user[0][“DisplayName”, “Description”] Then you will get name and descriptions, good way pinpoint fields you want to fetch

If you want to edit the information in the Array

$user[2]["Description"] = "Engineer / Technician"

If you want to delete information

$user[2].Remove("Description")