?
Solved

learner question: array(key,value)

Posted on 2005-03-26
8
Medium Priority
?
3,743 Views
Last Modified: 2010-08-05
I have flat files whose contents regularly move from one file to another or a different location in the same file or are deleted. The contents of those files could be compared to containers holding other containers, down from 1 to 5 levels and it is those containers that move or are deleted.

Questions:
Are PHP arrays suitable to trace these containers through their key attribute? For example if one container moves to another file or to another position in the same file (another array or sub-array) can it keep its key automatically?

When moving, can a container's key and value be inserted in a precise location in another array or sub-array?

When saving files from arrays, can the keys be saved in one file and the values in another?

If PHP arrays are suitable, can you show me some example of code for this particular application?
0
Comment
Question by:rblampain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Assisted Solution

by:namitthapa
namitthapa earned 150 total points
ID: 13638731
Well i didn't get what does container mean in your question.But answering your question it is possible to a key and value in another array in a precise location.Like wise we can save file from array also.
0
 

Author Comment

by:rblampain
ID: 13638896
Another comparison of the files I am talking about is that of a text file divided into words, sentences, paragraphs, chapters and so on, sometimes what is moved is only a word, sometimes it's a sentence or a paragraph etc.
0
 
LVL 11

Accepted Solution

by:
ZhaawZ earned 825 total points
ID: 13642953
I'm not sure if I understood what you need.

> When saving files from arrays, can the keys be saved in one file and the values in another?
Do you really need this? You may make a PHP file that will contain an array with keys and values.
0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

Author Comment

by:rblampain
ID: 13643370
To ZhaawZ:
I don't have a clear understanding of "keys" yet but what I have to do is to put into arrays all the words, sentences etc (in my last example) and allow them to be moved to other parts of a multi-dimensional array with a reference attached to them showing where they come from. I thought the "keys" might come handy here. So, to answer your question, yes I need it.  It's also needed as a log of the history of the files, this is why I need a separate file with the "keys". Not long ago a versioning system was contemplated but found completely unsuitable.
0
 
LVL 1

Assisted Solution

by:pkphilip
pkphilip earned 525 total points
ID: 13660373
I am not entirely sure I understand your question, but I will try and address this whole issue of array keys. An array is defined something like this:

$first_array = array();
$first_array["line1"] = "This is the contents of line 1"';

Here "line1" is the key and "This is the contents of line 1" is the value.

if you have two arrays and you want to copy the key and value from one array to the second array, you can do something like this:

$second_array = array();
$second_array["line1"] = $first_array["line1"];



0
 

Author Comment

by:rblampain
ID: 13661117
Thanks to pkphilip. This answers part of my questions.

My second question involves the following arrays example:

$f1 = array("l1" => array("l2" => array("l3" => array("l4" => array("l5" => array())))));
$f2 = array("l1" => array("l2" => array("l3" => array("l4" => array("l5" => array())))));

as I understand it, this is the way to define a multi-dimensional array, I've called the arrays $f1 and $f2 and I've made what I think is 5 levels of dimensions, these dimensions are the containers I mentioned earlier. What I want to do is, for example, move someting from $f1
level 3 to $f2 level 3,  this would automatically imply moving everyting below in level 4 and level 5.
Is this doable? Is this a normal use of arrays? Are there functions that do this or would it need to be done as a script?
Again, a few examples are most welcome.
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 13664704
Array is one of types. "Multidimensional arrays" actually are just arrays of arrays. For example:

$arr1[0] = 'one';
$arr1[1] = 'two';
$arr1[2] = 'three';

$arr2[0] = $arr1;
$arr2[1] = $arr1;  // this will make array(array('one', 'two', 'three'), array('one', 'two', 'three'))
unset($arr2[1]);   // this will delete $arr2[1].. $arr2 is now array(array('one', 'two', 'three'))

$arr3 = $arr1; // this will "copy" $arr1
$arr4 = $arr2; // this will "copy" $arr2 (with all "subarrays")


You may use array variables the same way you use other variables.
0
 
LVL 1

Expert Comment

by:namitthapa
ID: 13679386
I wondered Why Did u accept my comment as an answer.Actually these time i was quite busy so i didn't have time to return here.Any Way Thank you.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question