Jump to content

اجيب القيمة الثانية من الجدول عن طريق القيمة الاولي


Recommended Posts

سلام عليكم

ابي اجيب القيمة الثانية من الجدول عن طريق القيمة الاولي

يعني مثلا انا عندي جدول كدا

local test = { 
[1] = {"1","2"},
[2] = {"3","4"},
}

وابي اجيب قيمة 2 , عن طريق قيمة 1

يعني ابحث في الجدول عن طريق 1

مثال مثلا

2 = test[find(1)][1]

 

Link to comment
3 minutes ago, Abdul KariM said:

الحين عندك بالجدول القيمة الاولى فيها 1 و 2

انت جبت 1 وتبي تجيب 2 ؟

انا معايا الكولمن رقم 1 من الجدول الي هو "1" ابي اجيب الكولمن التاني عن طريق الكولمن الاول 

Link to comment
local test = {};
test[1]={"1","2"};
test[2]={"3","4"};

function getSecondValueByFirstValue(firstValue,aTable)
	if (firstValue and aTable) then
		for i=1,#aTable do
			if (aTable[i][1] == firstValue) then
				return aTable[i][2]
			end
		end
	end
	return false
end

--> Example | مثال
print(	getSecondValueByFirstValue("3",test)	); -- prints --> 4

 

Edited by NX_CI
Link to comment
43 minutes ago, NX_CI said:

local test = {};
test[1]={"1","2"};
test[2]={"3","4"};

function getSecondValueByFirstValue(firstValue,aTable)
	if (firstValue and aTable) then
		for i=1,#aTable do
			if (aTable[i][1] == firstValue) then
				return aTable[i][2]
			end
		end
	end
	return false
end

--> Example | مثال
print(	getSecondValueByFirstValue("3",test)	); -- prints --> 4

 

مع اني جبتها بس كفو علي الوظيفة ض2

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...