silly php question...
why cant i do this?
echo Auth::getFullUser()[ 'country' ];
instead you have to do this
$user = Auth::getFullUser();
echo $user[ 'country' ];
The following piece of code gives a segmentation fault when allocating memory for the last arg. What am I doing wrong? Thanks.
int n_args = 0, i = 0;
while (line[i] != '\0')
{
if (isspace(line[i++]))
n_args++;
}
for (i = 0; i < n_args; i++)
command = malloc (n_args * sizeof(char*));
char* arg = NULL;
arg = strtok(line, " \n");
while (arg != NULL)
{
arg = strtok(NULL, " \n");
command[i] = malloc ( (strlen(arg)+1) * sizeof(char) );
strcpy(command[i], arg);
i++;
}
Thanks.
I am trying to decide on a data structure for an array that has a date for the key and the amount of bandwidth consumed as values.
examples
Key Consumed Policy
October 50 Basic
November 75 Basic
December 100 Basic
Some months, but not all, will have more than one policy. In that case, I need break them down by policy once the total is shown. So for the above example, assume December had 3 policies. The table i construct from my array would then need to show:
Key Consumed Policy
October 50 Basic
November 75 Basic
December 100 ..
December 25 Basic
December 25 Extended
December 50 Premium
Could all this data be represented in an array ?
$myArray['december'] would be a different data structure than the others because it would need a last entry, probably another array, that had the policy names as keys and the amount of data consumed as values. Does PHP allow for arrays that are not structured uniformly? i.e. key october and November have only 2 entries under their key while December has 2 entries plus a 3rd which is an additional array.
My best guess is something like:
Array (
[October] => "50", "Basic"
[November] => "75", "Basic"
[December] => "100", "..", Array( [Basic] => 25
[Extended] =>25
[Premium] => 50
)
)
My question is if this is possible and how to declare it and populate it with values with PHP. Thanks in advance for any clarifications or assistance!
OK so my code is here: http://www.so.pastebin.com/m7V8rQ2n
What I want to know... let's say I have an image which I can redraw on tiles... is there a way to check for future tiles so I DON'T go out of bounds of my already defined tile map?
Like if I were at the edge of a map... it would NOT let me go past it?
Thanks.
< input type='text' id='txt' name='txtName' size='20' value='testing'/>
<script type="text/javascript" language='javascript'>
var val = document.getElementsByName('txtName');
alert(val[0].value);
alert(window.txtName.value);
</script>
In above code we are using
alert(val[0].value);
alert(window.txtName.value);
these two ways for getting value from object. What is the difference b/w both ways and which way is best.
Hello,
I'm not able to understand the following multi-dimensional code. Could someone please clarify me?
int[][] myJaggedArr = new int [][]
{
new int[] {1,3,5,7,9},
new int[] {0,2,4,6},
new int[] {11,22}
};
May I know how it is different from the following code?
int[][] myArr = new int [][] {
{1,3,5,7,9},
{0,2,4,6},
{11,22} };
Hi,
I need to find common elements between two arrays. My code is:
$sql="SELECT DISTINCT fk_paytbl_discounts_discountid as discountid from paytbl_discounts_students WHERE fk_vtiger_cf_601='".$categoryid."'";
$discountstudentinfo=$objdb->customQuery($sql,false);
$sql1="SELECT DISTINCT fk_paytbl_discounts_discountid as discountid from paytbl_discounts_variants WHERE fk_vtiger_products_productid='".$variantid."'";
$discountvariantinfo=$objdb->customQuery($sql1,false);
$commondiscount=array_intersect($discountvariantinfo,$discountstudentinfo);
First arrayArray
(
[0] => Array
(
[discountid] => 2
)
[1] => Array
(
[discountid] => 8
)
[2] => Array
(
[discountid] => 5
)
[3] => Array
(
[discountid] => 4
)
)
Second arrayArray
(
[0] => Array
(
[discountid] => 1
)
[1] => Array
(
[discountid] => 5
)
)
Common arrayArray
(
[0] => Array
(
[discountid] => 1
)
[1] => Array
(
[discountid] => 5
)
)
Common array should have only discountid 5 but its showing 1 also.
Please help me on this
Thanks
The basic pseudo code looks like this:
void myFunction()
{
int size = 10;
int * MyArray;
MyArray = new int[size];
cout << size << endl;
cout << sizeof(MyArray) << endl;
}
The first cout returns 10, as expected, while the second cout returns 4.
Anyone have an explanation?
Suppose I have an array of nodes (objects). I need to create a duplicate of this array that I can modify without affecting the source array. But changing the nodes will affect the source nodes. Basically maintaining pointers to the objects instead of duplicating their values.
// node(x, y)
$array[0] = new node(15, 10);
$array[1] = new node(30, -10);
$array[2] = new node(-2, 49);
// Some sort of copy system
$array2 = $array;
// Just to show modification to the array doesn't affect the source array
array_pop($array2);
if (count($array) == count($array2))
echo "Fail";
// Changing the node value should affect the source array
$array2[0]->x = 30;
if ($array2[0]->x == $array[0]->x)
echo "Goal";
What would be the best way to do this?
C99 provides a feature to initialize arrays by using both element-by-element & designated
method together as:
int a[] = {2,1,[3] = 5,[5] = 9,6,[8] = 4};
On running the code:
#include <stdio.h>
int main()
{
int a[] = {2,1,[3] = 5,[0] = 9,4,[6] = 25};
for(int i = 0; i < sizeof(a)/sizeof(a[0]); i++)
printf("%d ",a[i]);
return 0;
}
(Note that Element 0 is initialized to 2 and then again initialised by designator [0]
to 9)
I was expecting that element 0(which is 2) will be replaced by 9(as designator [0] = 9)
and hence o/p will become
9 1 0 5 4 0 25
Unfortunately I was wrong as o/p came;
9 4 0 5 0 0 25
Any explanation for unexpected o/p?
Hi folks,
I'm looking for a way to read in c++ a text file containing numpy arrays and put the data into vector , can anyone help me out please ?
Thanks a lot.
Archy
hi can anybody tell me the error in this?
#include<stdio.h>
int main()
{
char a[]="abcdefgh";
int i=0;
int n=strlen(a);
char *first;
char *second;
char *c;
*first=a[0];
*second=a[7];
for(i=0;i<=n/2;i++)
{
*c=*first;
*first=*second;
*second=*c;
first++;
second--;
}
for(i=0;i<=7;i++)
{
printf("%c",a[i]);
}
}
Hello,
I have a strange problem which I can't fix:
A field:
private boolean[][][] gaps;
Constructor (1st line):
gaps = new boolean[NOBARRICADES][WIDTH][HEIGHT];
Constructor (2nd line):
for (int i = 0; i < NOBARRICADES; i++) {
JAVA throws an error for the 2nd line, saying:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
Does it have anything to do with JAVA syntax (the mistake is in these lines of code) or I should look for the problem somewhere else?
Is there an easy way to do array manipulation in gsettings? I am comparing gsettings to OS X's defaults command that offers the defaults domain --array key overwrite-value and defaults domain --array-add key added-value interface for manipulating arrays.
As far as I can tell there is only gsettings set domain key "['overwrite-value']" available to gsettings. Not really pretty for when you want to add or remove one entry from an array.
I have seen a suggestion that allow me to add to an array, but I would rather use a interface if there is one.
I have a text file that contains a number of the following:
<ID>
<Time 1> --> <Time 2>
<Quote (potentially multiple line>
<New Line Separator>
<ID>
<Time 1> --> <Time 2>
<Quote (potentially multiple line>
<New Line Separator>
<ID>
<Time 1> --> <Time 2>
<Quote (potentially multiple line>
<New Line Separator>
I have a very simple regex for stripping these out into a constant block so it's just:
<Quote>
<Quote>
<Quote>
What I'd like to do is present the quotes as a block to the user, and have them select it (using jQuery.fieldSelection) and then use the selected content to back out to the original array, so I can get timing and IDs.
Because this has to go out to HTML, and the user has to be able to select the text on the screen, I can't do anything like hidden divs or hidden input fields. The only data I will have is the character range selected on screen.
To be specific, this is what it looks like:
1
0:00 --> 0:05
He was bored. So bored. His great intellect, seemingly inexhaustible,
was hungry for new challenges but he was the last of the great innovators
2
0:05 --> 0:10
- society's problems had all been solved.
3
0:11 --> 0:20
All seemingly unconnected disciplines had long since been found to be related in
horrifically elusive and contrived ways and he had mastered them all.
And this is what I'd like to present to the user for selection:
He was bored. So bored. His great
intellect, seemingly inexhaustible,
was hungry for new challenges but he
was the last of the great innovators -
society's problems had all been
solved. All seemingly unconnected
disciplines had long since been found
to be related in horrifically elusive
and contrived ways and he had mastered
them all.
Has anyone com across something like this before? Any ideas how to take the selected text, or selection position, and go backwards to the original meta-data?
I'm using vb.net 2008 edition and i was wondering if there a way to convert an array type to another array type. For instance say i dim an array as string and then want to convert the array to the integer data type for sorting, how would i go about this?
A PHP array can have arrays for its elements. And those arrays can have arrays and so on and so forth. Is there a way to find out the maximum nesting that exists in a PHP array? An example would be a function that returns 1 if the initial array does not have arrays as elements, 2 if at least one element is an array, and so on.
Hello,
I got a 2-dimentional array containing boolean values written in C#.
The cols and rows of the array are to be determined by the user upon creation of the array.
I then want to print out the array and it´s containing values onto the console in order.
For example like this, how is this done in C#?
ROWS - COLS - VALUE
1 - A - True
1 - B - True
1 - C - True
1 - D - True
2 - A - True
2 - B - False
2 - C - False
2 - D - True
This was very interesting question recently asked me to during my session at TechMela Nepal. The question is what is the difference between GRANT and WITH GRANT when giving permissions to user.Let us first see syntax for the same.GRANT:USE master;GRANTVIEW ANY DATABASETO username;GOWITH GRANT:USE master;GRANTVIEW ANY DATABASETO username WITHGRANTOPTION;GOThe difference between both of this option [...]...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.
What's the difference between MariaDB and MySQL? I'm not very familiar with both. I'm primarily a front end developer for the most part.
Are they syntactically similar? Where do these two query languages differ?
Wikipedia only mentions the difference between licensing:
MariaDB is a community-developed branch of the MySQL database, the
impetus being the community maintenance of its free status under GPL,
as opposed to any uncertainty of MySQL license status under its
current ownership by Oracle.
I have the following sources enabled: main, universe, restricted and multiverse. On Ubuntu Software Center on 11.10 I see two packages for Emacs:
The GNU Emacs editor (metapackage)
The GNU Emacs editor
What is the difference between metapackage version and non-metapackage one?
By the way, this thread What differences are there between the various version of Emacs available? also explains the difference between two Emacs versions: Emacs and Emacs-snapshot, and interestingly I don't see these packages now on my Ubuntu Software Center.
Could someone please explain quite clearly the difference between a port and a socket. I know that a port serves as a door into the network for an application
process and that the application process uses a socket connection to the given port number to handle network communication but when you have multiple processes listening on a single port number, I am finding it difficult to understand the difference between the socket and the port and how they all fit together.
Earlier I wrote blog post SQL SERVER Difference Between GETDATE and SYSDATETIME which inspired me to write SQL SERVER – Difference Between DATETIME and DATETIME2. Now earlier two blog post inspired me to write this blog post (and 4 emails and 3 reads from readers). I previously populated DATETIME and DATETIME2 field with SYSDATETIME, [...]...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.
Perhaps this is more of a math question than a MATLAB one, not really sure. I'm using MATLAB to compute an economic model - the New Hybrid ISLM model - and there's a confusing step where the author switches the sign of the solution.
First, the author declares symbolic variables and sets up a system of difference equations. Note that the suffixes "a" and "2t" both mean "time t+1", "2a" means "time t+2" and "t" means "time t":
%% --------------------------[2] MODEL proc-----------------------------%%
% Define endogenous vars ('a' denotes t+1 values)
syms y2a pi2a ya pia va y2t pi2t yt pit vt ;
% Monetary policy rule
ia = q1*ya+q2*pia;
% ia = q1*(ya-yt)+q2*pia; %%option speed limit policy
% Model equations
IS = rho*y2a+(1-rho)yt-sigma(ia-pi2a)-ya;
AS = beta*pi2a+(1-beta)*pit+alpha*ya-pia+va;
dum1 = ya-y2t;
dum2 = pia-pi2t;
MPs = phi*vt-va;
optcon = [IS ; AS ; dum1 ; dum2; MPs];
He then computes the matrix A:
%% ------------------ [3] Linearization proc ------------------------%%
% Differentiation
xx = [y2a pi2a ya pia va y2t pi2t yt pit vt] ; % define vars
jopt = jacobian(optcon,xx);
% Define Linear Coefficients
coef = eval(jopt);
B = [ -coef(:,1:5) ] ;
C = [ coef(:,6:10) ] ;
% B[c(t+1) l(t+1) k(t+1) z(t+1)] = C[c(t) l(t) k(t) z(t)]
A = inv(C)*B ; %(Linearized reduced form )
As far as I understand, this A is the solution to the system. It's the matrix that turns time t+1 and t+2 variables into t and t+1 variables (it's a forward-looking model). My question is essentially why is it necessary to reverse the signs of all the partial derivatives in B in order to get this solution? I'm talking about this step:
B = [ -coef(:,1:5) ] ;
Reversing the sign here obviously reverses the sign of every component of A, but I don't have a clear understanding of why it's necessary. My apologies if the question is unclear or if this isn't the best place to ask.