473,770 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is $Settings['string'] An Example Of An Array?

MBS
Greetings. I'm still pretty new to PHP and I have a question. I know that
variables are preceeded by a "$" (dollar sign). Typically, a variable has
one value, unless it is an array. Then it is essentially a pointer to
numerous values sequential in memory. The code I'm looking at now is using
the same variable name, but assigning a different "index" to it, if you
will.

For example, I see the following:

$settings['use_default_im ages']
$settings['doctype']
$settings['theme_url']

And many more.

What is this feature called in PHP? I looked at the reference on php.net
and it isn't anywhere to be found under arrays.

Thank you
Nov 2 '05 #1
7 1779
MBS wrote:
Greetings. I'm still pretty new to PHP and I have a question. I know that
variables are preceeded by a "$" (dollar sign). Typically, a variable has
one value, unless it is an array. Then it is essentially a pointer to
numerous values sequential in memory. The code I'm looking at now is using
the same variable name, but assigning a different "index" to it, if you
will.

For example, I see the following:

$settings['use_default_im ages']
$settings['doctype']
$settings['theme_url']

And many more.

What is this feature called in PHP? I looked at the reference on php.net
and it isn't anywhere to be found under arrays.
This is an array which uses a string as index instead of an int. This is
called associative arrays
Thank you

Nov 2 '05 #2
Użytkownik "MBS" <mb*@mbs.net> napisał w wiadomo¶ci news:43******** *************** @authen.white.r eadfreenews.net ...
What is this feature called in PHP?


It is called associative array.

--
greets
T
Nov 2 '05 #3
Actually, there is only one type of array in PHP and it is really an
ordered map.

PHP maps keys to values and indexes to values.

PHP arrays can appear to behave a little weird if you are used to
'normal' arrays, but they are very flexible once you get the hang of
them. Here are a few things to watch out for:

$stuff=array();
// you now have an empty array
// not usually necessary as simply setting an array member will create
it

$stuff[]="Fred";
// Now your array has one element with an index of 0

$stuff[14]="Bert";
// now your array has 2 elements, indexes 0 and 14

$stuff[] = "Anne";
// 0, 14, 15

$stuff["phone"]="0123456789 ";
// 0, 14, 15, 16
// but $stuff[16] get you the same thing as $stuff['phone']

// note that there is no $stuff[3] for example.
// trying to use it will cause an error
// also, deleting $stuff[15] will leave you with 0, 14, 16 - the gaps
don't close up
// have a play around - var_dump($stuff ) will show you what you have in
the array.

Ian

Nov 2 '05 #4
In our last episode,
<43************ ***********@aut hen.white.readf reenews.net>,
the lovely and talented MBS
broadcast on alt.php:
Greetings. I'm still pretty new to PHP and I have a question. I know that
variables are preceeded by a "$" (dollar sign). Typically, a variable has
one value, unless it is an array. Then it is essentially a pointer to
numerous values sequential in memory. The code I'm looking at now is using
the same variable name, but assigning a different "index" to it, if you
will. For example, I see the following: $settings['use_default_im ages']
$settings['doctype']
$settings['theme_url'] And many more. What is this feature called in PHP?


Pretty much the same thing it is called in Perl or any number
of other language. It is a hash (or associative array, if you
like big words or you are looking them up in an index).

I'm pretty sure you are used to arrays with number indices:

$a[0], $bugbear[15], $pinky[$i] where $i is an integer.

Associative arrays are very similar, but use strings as
indices. You have offered some examples, and $settings[$str]
is another where $str is a string. The strings used as indices
are called "keys" and they are *associated* with "values."

Now you probably have noticed, integers have a natural order.
But strings don't. So you have to be very careful if you ever
think of trying to do something like sort an associate array or
try to form and idea of "first," "last," or "next" in relation
to an associative array. There is no general guarantee of order
in an associate array.

Naturally, it seldom makes any sense to try to do arithmetic
on hash keys. In other words, you may be used to the idea
that if $a[$n] is a value in an array $a[$n+1] is the "next"
value (if there is one). But if you $jimmy['age'], then
$jimmy['age' + 1] is most likely nonsense. You can do
string operations on keys, although you may or may not ever
find a situation in which it is useful to do so (i.e.
$jimmy['ag' . 'e'] = $jimmy['age']). In particular,
if first you do $jimmy['age'] = 24; and then
$jimmy['apt'] = 1191; $jimmy['age' + 1] in general is not
equal to $jimmy['apt'].

Associative arrays are very good for operations with things
like databases and other sets of related data. It is much
easier to deal with $jimmy['age'] than to try to remember
whether age is $jimmy[5] or $jimmy[6]. Generally you don't care
whether Jimmy's age or his apartment number comes first in the
record, you just want to be sure you don't get them confused.

--
Lars Eighner ei*****@io.com http://www.larseighner.com/
I don't see posts from or threads started from googlegroups.
War on Terrorism: Treat Readers like Mushrooms
"DO NOT USE photos on Page 1A showing civilian casualties from the U.S. war
on Afghanistan." -Memo, _Panama City_ (FL) _News Herald_
Nov 2 '05 #5
Ian B wrote:
$stuff["phone"]="0123456789 ";
// 0, 14, 15, 16
// but $stuff[16] get you the same thing as $stuff['phone']


No, it won't. Index 16 will not be defined unless specified. If you want
$stuff[16] to return the same value as the 'phone' key, you should define
both:

$stuff['phone'] = 12345;
$stuff[16] =& $stuff['phone'];
$stuff['phone'] =& $stuff[16];

$stuff['phone'] .= 6;
$stuff[16] .= 7;
print $stuff[16]; // 1234567
print $stuff['phone']; // 1234567
JW

Nov 2 '05 #6
On Wed, 02 Nov 2005 05:12:34 -0600, Lars Eighner <ei*****@io.com > wrote:
Now you probably have noticed, integers have a natural order.
But strings don't. So you have to be very careful if you ever
think of trying to do something like sort an associate array or
try to form and idea of "first," "last," or "next" in relation
to an associative array. There is no general guarantee of order
in an associate array.


PHP differs from Perl here, in that the key ordering is preserved, in the
order that the keys were assigned (or you can modify the ordering e.g. with
ksort).
--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Nov 2 '05 #7

MBS wrote:
Greetings. I'm still pretty new to PHP and I have a question. I know that
variables are preceeded by a "$" (dollar sign). Typically, a variable has
one value, unless it is an array. Then it is essentially a pointer to
numerous values sequential in memory. The code I'm looking at now is using
the same variable name, but assigning a different "index" to it, if you
will.

For example, I see the following:

$settings['use_default_im ages']
$settings['doctype']
$settings['theme_url']

And many more.

What is this feature called in PHP? I looked at the reference on php.net
and it isn't anywhere to be found under arrays.


Arrays with string indices are called associative arrays or hash
tables. The term in VB-speak I believe is dictionary.

Nov 2 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
34146
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found Encoding.Convert, but that needs byte arrays. Thanks, /Ger
4
3165
by: Sai | last post by:
Hi, I am using VSTO 2005 Beta for building an excel application. I added application configuration file to the project (app.config) and it has the following section in it. <configuration> <appSettings> <add key="serv" value="test" /> </appSettings> </configuration>
1
1347
by: Curtis | last post by:
I am using the application settings example @ http://msdn.microsoft.com/msdnmag/issues/05/04/AdvancedBasics/default.aspx . My application needs to save a user name and password in encrypted format into the XML settings file. I modified the settings.vb class to include code that encrypts and decrypts the user name and password as needed. The problem I am having is getting the username and password to store as encrypted in the XML document....
13
1864
by: Eric Renken | last post by:
I currently use statements like this in my 1.1 code. System.Configuration.ConfigurationSettings.AppSettings I use this in DLLs that are referenced by the application. The application has this data in its app.config file. I would like to switch to the new Setting files in 2.0, but I don't know if I can access these settings from a different DLL. I can't make a reference in the DLL back to the application because that would create a...
3
1676
by: יניב | last post by:
how could i write this into a sting : strXML = "<?xml version='1.0'?>\n"; thanks
3
18331
by: Nayan Mansinha | last post by:
Hi All How can I store an array of objects in my C# Application.Settings? I have CMyObject class for which an array is created: CMyObject arr = new CMyObject; arr = new CMyObject(); arr.Name = "One";
3
3817
by: nasse | last post by:
Would you please help me in how to get the remaining column values so that I will be able to echo each value in my pages. Right now, my function is set to return just to return one field's value (line 13) but I want to do the same for all the remaining fields. How do I write loopings like foreach .... class Setting extends Domain { function __construct() { parent::__construct( 'Settings', array 'Settings_id', 'webSite', 'Slogan',...
2
5348
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi Is there any way to Read an INIFile from a string or Stream instead of a physical file ??? I want to read the INIFile into a string then store in a db but when I read the string from the db or save string to the db I don't want to have to copy the string to a file to use the WritePrivateProfileString and GetPrivateProfileString. Is there a way around this instead of writing my own class to operate on a string or stream ???
3
9747
by: =?Utf-8?B?Sm9u?= | last post by:
Hello, I have tried to use the app.config and settings.cs files to store my data (which I want to be user changeable at runtime). I can write to (what I assume is an object in memory) and it does seem to work...however, once the application is closed and reopened the changes are lost. How do I persist the information? Here is some sample code using both methods: //////Using Properties.Settings///////
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.