473,408 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Problem with array and variables as index

Hi,
i have a problem determining a matrix value by using a variable as
index of the array.:
I'm using php 4.3.11 + win xp SP2 + apache 1.3.33
I wrote a class in which there is an array defined as follows. There is
also a method to get the value of a given element of the array.

class obj1 {
.....

foerach (...) {
$this->_rows[] = array($key=>$value);
}

function _foo ($key, $offset=0) {
....
return $this->_rows[$offset][$key];

}
......
}

Then, I have another class which contains an istance of obj1 and a kind
of wrapper to the _foo method:

class obj2 {
....
$this->obj =& new obj1;
....
function bar ($key, $offset=0) {
//eg. key='test' offset=0
echo $this->obj->_foo($key, $offset);

}
....
}

If I call the bar('test') method I get a NULL value, but if in the _foo
method i put echo $key.$offset it prints correctly 'test0'. Also, if I
put in _foo echo $this->_rows[0]['test'] it prints the correct value,
BUT if I echo $this->_rows[$offset][$key] it prints nothing!!
I can't understand where the problem is.... is it a bug?

Thanks for your answers!

Jul 17 '05 #1
0 1179

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

Similar topics

22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
10
by: dof | last post by:
I'm trying the following and having problems. I get errors on the array declaration lines. Something about an array must have at least one element. Thanks in advance. D #include stuff .... ...
6
by: Edd Dawson | last post by:
Hi. I have a strange problem involving the passing of command line arguments to a C program I'm writing. I tried posting this in comp.programming yesterday but someone kindly suggested that I'd...
7
by: Peter | last post by:
I want to create a multidemensional arraylist. Seeing as they don't exist I was wondering if there is a way to create a class that works like one. I basically want to use it like this Dim...
0
by: Fei Liu | last post by:
Yet another problem to deal with dynamic data type that can only be determined at run time. For a netCDF file (a scientific data format), a variable is defined with its associating dimensions, i.e....
3
by: new214 | last post by:
heya all, ive got abit of a problem. Im doin a system in asp- which works on a test server- but when on moving my application to a development server- it throws the following error messages where I...
22
by: sam_cit | last post by:
Hi Everyone, I have the following structure in my program struct sample { char *string; int string_len; };
9
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
10
by: SoulIntruder | last post by:
Hello folks. I have a beginners question. I have such script: <?php $User = $_POST; $Password = $_POST; $Database = $_POST;
14
by: chromis | last post by:
Hi, I've been trying to implement a more OOP oriented approach to dealing with user security on one of my websites, and I am trying to validate the user against an array of roles, however I am...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.